Giter Club home page Giter Club logo

Comments (8)

fuchaoqun avatar fuchaoqun commented on June 3, 2024

要调用FoobarModel, 直接 new FoobarModel()就可以了;

引入公用方法库,如果是个类的话,直接配置在$config['_class']里面自动加载就可以。
$config['_class']['Foobar'] = '/path/to/Foobar'

from colaphp.

ehvu avatar ehvu commented on June 3, 2024

Model如下,
class IndexModel extends Cola_Model
{
protected $_table = 'v9_admin';

public function test()
{
    try {
        $data = $this->sql("select * from v9_admin limit 5;");
        return $data;
    } catch (Exception $e) {
        die($e);
    }
}

}
Controller 如下
class IndexController extends Cola_Controller
{
public function indexAction()
{
$model = new IndexModel();

    var_dump($model->test());
}

}

结果返回 false
这是个什么原因呢。。。

from colaphp.

fuchaoqun avatar fuchaoqun commented on June 3, 2024

先确定test()方法有没有调用,然后看一下报错信息,应该需要在config里面配置一下db的信息,然后在model里面指定$_db是哪个配置信息

from colaphp.

ehvu avatar ehvu commented on June 3, 2024

配置信息如下
'_db' => array(
'adapter' => 'Mysql',
'params' => array(
'host' => '127.0.0.1',
'port' => 3306,
'user' => 'root',
'password' => '',
'database' => 'ppp_cms',
'charset' => 'utf8',
'persitent' => true
)
),

以下是直接打印的
$model = new IndexModel()
print_r($model)

IndexModel Object
(
[_table:protected] => v9_admin
[_db:protected] => _db
[_pk:protected] => id
[_cache:protected] => _cache
[_ttl:protected] => 60
[_validate:protected] => Array
(
)

[error] => Array
    (
        [code] => 1045
        [msg] => Access denied for user 'test'@'localhost' (using password: NO)
    )

[db] => Cola_Ext_Db_Mysql Object
    (
        [config] => Array
            (
                [adapter] => Mysql
                [params] => Array
                    (
                        [host] => 127.0.0.1
                        [port] => 3306
                        [user] => root
                        [password] => 
                        [database] => ppp_cms
                        [charset] => utf8
                        [persitent] => 
                    )

                [host] => 127.0.0.1
                [port] => 3306
                [user] => test
                [password] => 
                [database] => test
                [charset] => utf8
                [persistent] => 
                [options] => Array
                    (
                    )

            )

        [conn] => 
        [query] => 
        [debug] => 
        [log] => Array
            (
            )

    )

)

另:这些都是参考 1.2GA的demo写的,

from colaphp.

fuchaoqun avatar fuchaoqun commented on June 3, 2024

'_db' => array(
'host' => '127.0.0.1',
'port' => 3306,
'user' => 'root',
'password' => '',
'database' => 'ppp_cms',
'charset' => 'utf8',
'persitent' => true
)

试一下这个,2.0之后有些代码不兼容了

from colaphp.

ehvu avatar ehvu commented on June 3, 2024

超群君 ,非常感谢。
看了你在infoq上的演讲视频才知道ColaPHP。
感谢。
将继续深入学习下ColaPHP,准备用在实际项目中。期待2.0GA版

from colaphp.

fuchaoqun avatar fuchaoqun commented on June 3, 2024

2.0已经GA了,很多朋友在用,会比之前的版本顺手许多。

from colaphp.

ehvu avatar ehvu commented on June 3, 2024

感谢超群君的分享

from colaphp.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.