Yii Property "CDbConnection.tableprefix" is not defined.

2014-04-15 18:34:04

I’m new to the Yii framework. I created a table named ‘tbluser’, had set the tablePrefix to ‘tbl’ in main.php in the ‘db’ array. When I ran the model command from the yii shell script , I got the following:

QQ图片20140415221014
Stack Trace:

[php]
#0 W:\newwamp\www\shop\framework\YiiBase.php(220): CComponent->set("tableprefix", "tbl_")
#1 W:\newwamp\www\shop\framework\base\CModule.php(386): YiiBase::createComponent(array("class" =>"CDbConnection","connectionString" => "mysql:host=localhost;dbname=testdrive", "emulatePrepare" => true, "username" => "root", …))
#2 W:\newwamp\www\shop\framework\base\CModule.php(103): CModule->getComponent("db")
#3 W:\newwamp\www\shop\shop\protected\controllers\IndexController.php(7): CModule->
get("db")
#4 W:\newwamp\www\shop\framework\web\actions\CInlineAction.php(49): IndexController->actionIndex()
#5 W:\newwamp\www\shop\framework\web\CController.php(308): CInlineAction->runWithParams(array("r" => "index/index"))
#6 W:\newwamp\www\shop\framework\web\CController.php(286): CController->runAction(CInlineAction)
#7 W:\newwamp\www\shop\framework\web\CController.php(265): CController->runActionWithFilters(CInlineAction, array())
#8 W:\newwamp\www\shop\framework\web\CWebApplication.php(282): CController->run("index")
#9 W:\newwamp\www\shop\framework\web\CWebApplication.php(141): CWebApplication->runController("index/index")
#10 W:\newwamp\www\shop\framework\base\CApplication.php(180): CWebApplication->processRequest()
#11 W:\newwamp\www\shop\shop\index.php(15): CApplication->run()
[/php]

I removed the tablePrefix entry from main.php. When I ran the model command again, it shows what i want, i have wrote var_dump(Yii::app()->db); in IndexController.php. it worked!

object(CDbConnection)[13] public 'connectionString' =>string'mysql:host=localhost;dbname=testdrive'(length=37)public 'username' =>string'root'(length=4)public 'password' =>string'528126'(length=6)public 'schemaCachingDuration' =>int0public 'schemaCachingExclude' =>array(size=0)emptypublic 'schemaCacheID' =>string'cache'(length=5)public 'queryCachingDuration' =>int0public 'queryCachingDependency' =>nullpublic 'queryCachingCount' =>int0public 'queryCacheID' =>string'cache'(length=5)public 'autoConnect' =>booleantruepublic 'charset' =>string'utf8'(length=4)public 'emulatePrepare' =>booleantruepublic 'enableParamLogging' =>booleanfalsepublic 'enableProfiling' =>booleanfalsepublic 'tablePrefix' =>nullpublic 'initSQLs' =>nullpublic 'driverMap' =>array(size=9) 'pgsql' =>string'CPgsqlSchema'(length=12) 'mysqli' =>string'CMysqlSchema'(length=12) 'mysql' =>string'CMysqlSchema'(length=12) 'sqlite' =>string'CSqliteSchema'(length=13) 'sqlite2' =>string'CSqliteSchema'(length=13) 'mssql' =>string'CMssqlSchema'(length=12) 'dblib' =>string'CMssqlSchema'(length=12) 'sqlsrv' =>string'CMssqlSchema'(length=12) 'oci' =>string'COciSchema'(length=10)public 'pdoClass' =>string'PDO'(length=3)private 'attributes' =>array*(size=0)emptyprivate* 'active' =>booleantrueprivate 'pdo' =>object(*PDO*)[*14*] *private* 'transaction' =>nullprivate 'schema' =>null*public* 'behaviors' =>array*(size=0)emptyprivate* 'initialized' (CApplicationComponent)=>booleantrueprivate 'e' (CComponent)=>null*private* 'm' (CComponent)=>null

Any idea why I encountered this?

Here’s what I have in main.php.

[php]’db’=>array(
‘class’=>’CDbConnection’,
‘connectionString’ => ‘mysql:host=localhost;dbname=testdrive’,
’emulatePrepare’ => true,
‘username’ => ‘root’,
‘password’ => ‘528126’,
‘charset’ => ‘utf8’,
‘tableprefix’ => ‘tbl_’,
),[/php]

Yii框架学习笔记(四)连接数据库

YII采用ORM(object-Relation Mapping)的设计模式进行数据库编程。 配置数据库连接 在protected/config/main.php文件中: [php]’db’=>array( ‘connectionString’=>’mysql:host=localhost;dbname=testdrive’, ’emulatePreare’=>true, ‘username’=>’root’, ‘password’=>”, ‘charset’=>’utf8’, ),[/php] 定义数据库操作类:models [php] class User extends CActiveRecord{ public static function model(CLASS){ return parent::model($className); } //静态方法model()是每一个AR类所必须的。 public function tableName(){ return ‘{{User}}’; } } ?>[/php]

ubuntu14.04 安装Wine1.7

打开终端执行一下命令,在安装过程中会提示你是否同意协议,点击Enter: sudo add-apt-repository ppa:ubuntu-wine/ppa sudo apt-get update && sudo apt-get install wine1.7