我已经在yii中为mysql数据库创建了所有模型,运行良好现在我想添加一个额外的数据库,即mssql 2000。几个小时后,我已经设置了php和pdo适配器。现在,我试图为mssql中的单个表创建一个模型。它不让我。我得到以下错误。

The table "[xxx Geo Limited\$Fixed Asset]" for active record class "FixedAsset" cannot be found in the database.



    private $_model;
2301
2302     /**
2303      * Constructor.
2304      * @param CActiveRecord $model the model instance
2305      */
2306     public function __construct($model)
2307     {
2308         $this->_model=$model;
2309
2310         $tableName=$model->tableName();
2311         if(($table=$model->getDbConnection()->getSchema()->getTable($tableName))===null)
2312             throw new CDbException(Yii::t('yii','The table "{table}" for active record class "{class}" cannot be found in the database.',
2313                 array('{class}'=>get_class($model),'{table}'=>$tableName)));
2314         if($table->primaryKey===null)
2315         {
2316             $table->primaryKey=$model->primaryKey();
2317             if(is_string($table->primaryKey) && isset($table->columns[$table->primaryKey]))
2318                 $table->columns[$table->primaryKey]->isPrimaryKey=true;
2319             else if(is_array($table->primaryKey))
2320             {
2321                 foreach($table->primaryKey as $name)
2322                 {
2323                     if(isset($table->columns[$name]))
2324                         $table->columns[$name]->isPrimaryKey=true;

我的模型称为FixedAsset,我在mssql中的表称为[xxx Geo Limited\$Fixed Asset]

最佳答案

解决了这个问题,在指定表时使用双引号

public function tableName()
    {
        //exit("help");
        return "[xxxGeo Limited\$Fixed Asset]";
    }

10-05 20:45
查看更多