yii初学,几个小问题求教

q503959 2014-07-18 12:45:46
Internal Server Error

CDbConnection.connectionString cannot be empty.

An internal error occurred while the Web server was processing your request. Please contact the webmaster to report this problem.

Thank you.


①首先是连数据库,出现了以上错误,protected/config/main.php代码如下
return array(

'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=yii',
'tablePrefix' =>'yii_',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',

)

);


controller里面一用$connection=Yii::app()->db;就出错,而用显式连接$connection=new CDbConnection('mysql:host=localhost;dbname=yii','root','');就没有问题

②model要引入?已经找遍了各种文档都没有说要引入的。。。。
我protected/models/DataModel.php里面代码如下
class DataModel extends CFormModel
{
public $employeeId;
public $firstName;
public $lastName;
public $title;
public $address;
public $email;
}


而controller里面$model=new DataModel();就报错如下

YiiBase::include(DataModel.php) [<a href='function.YiiBase-include'>function.YiiBase-include</a>]: failed to open stream: No such file or directory

An internal error occurred while the Web server was processing your request. Please contact the webmaster to report this problem.



顺便再求一下YII学习资料文档啊,网上找了好久都是没有入门级或者很繁琐的。因为工作问题,从THINKPHP转学YII,最近几天各种蛋疼,风格始终还没有适应过来
...全文
477 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiatsing 2014-07-24
  • 打赏
  • 举报
回复
楼上的没错 ,你把DB 那一坨 放到 'components' => array('db' => array('connectionString')) DB 是它的一个组件, 所有组件都写到这里面
yovinx 2014-07-18
  • 打赏
  • 举报
回复
'components' => array( 'db' => ..... )

4,251

社区成员

发帖
与我相关
我的任务
社区描述
国内外优秀PHP框架讨论学习
社区管理员
  • Framework
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧