Comments (8)
要调用FoobarModel, 直接 new FoobarModel()就可以了;
引入公用方法库,如果是个类的话,直接配置在$config['_class']里面自动加载就可以。
$config['_class']['Foobar'] = '/path/to/Foobar'
from colaphp.
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.
先确定test()方法有没有调用,然后看一下报错信息,应该需要在config里面配置一下db的信息,然后在model里面指定$_db是哪个配置信息
from colaphp.
配置信息如下
'_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.
'_db' => array(
'host' => '127.0.0.1',
'port' => 3306,
'user' => 'root',
'password' => '',
'database' => 'ppp_cms',
'charset' => 'utf8',
'persitent' => true
)
试一下这个,2.0之后有些代码不兼容了
from colaphp.
超群君 ,非常感谢。
看了你在infoq上的演讲视频才知道ColaPHP。
感谢。
将继续深入学习下ColaPHP,准备用在实际项目中。期待2.0GA版
from colaphp.
2.0已经GA了,很多朋友在用,会比之前的版本顺手许多。
from colaphp.
感谢超群君的分享
from colaphp.
Related Issues (11)
- 不知道做了那些更改?1.2GA的例子关于view的,在目前版本运行错误 HOT 3
- 能不能整个演示、范例? HOT 1
- ColaPHP 怎样与Crontab 结合使用
- ZeroRPC模块不能作为client跟zerorpc-python的server端通信 HOT 1
- config.php文件的_merge方法的BUG HOT 1
- 新框架ColaPHP HOT 1
- 老大 更新一下框架嘛 HOT 2
- Response Controller function status HOT 1
- Cola class function addNamespace HOT 1
- simple exampe please
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from colaphp.