我通常遵循 Yii 扩展:多语言行为指令,这是我的模型行为配置:
public function behaviors()
{
return array(
'ml' => array(
'class' => 'application.models.behaviors.MultilingualBehavior',
'langClassName' => 'CandidateLang',
'langTableName' => 'candidatelang',
'langForeignKey' => 'candidate_id',
'langField' => 'lang_id',
'localizedAttributes' => array('name', 'birth_place', 'home_city', 'intro'), //attributes of the model to be translated
'localizedPrefix' => 'l_',
'languages' => Yii::app()->params['languages'], // array of your translated languages. Example : array('fr' => 'Français', 'en' => 'English')
'defaultLanguage' => 'en', //your main language. Example : 'fr'
'createScenario' => 'insert',
'localizedRelation' => 'i18nCandidate',
'multilangRelation' => 'multilangCandidate',
'forceOverwrite' => false,
'forceDelete' => true,
'dynamicLangClass' => true, //Set to true if you don't want to create a 'PostLang.php' in your models folder
),
);
}
我得到一个 CDbException:在数据库中找不到活动记录类“CandidateLang”的表“{{candidatelang}}”。
这是触发错误的地方:
private $_model;
2253
2254 /**
2255 * Constructor.
2256 * @param CActiveRecord $model the model instance
2257 */
2258 public function __construct($model)
2259 {
2260 $this->_model=$model;
2261
2262 $tableName=$model->tableName();
2263 if(($table=$model->getDbConnection()->getSchema()- >getTable($tableName))===null)
2264 throw new CDbException(Yii::t('yii','The table "{table}" for active record class "{class}" cannot be found in the database.',
2265 array('{class}'=>get_class($model),'{table}'=>$tableName)));
2266 if($table->primaryKey===null)
2267 {
2268 $table->primaryKey=$model->primaryKey();
2269 if(is_string($table->primaryKey) && isset($table->columns[$table->primaryKey]))
2270 $table->columns[$table->primaryKey]->isPrimaryKey=true;
2271 else if(is_array($table->primaryKey))
2272 {
2273 foreach($table->primaryKey as $name)
2274 {
2275 if(isset($table->columns[$name]))
2276 $table->columns[$name]->isPrimaryKey=true;
我确保桌子在那里,并仔细检查了大小写和拼写。我什至尝试从架构中放置不同的表名,但没有任何运气!所以我猜这个调用会导致错误:
$model->getDbConnection()
,但我不知道为什么或如何修复它?