I have followed Yii extension: Multilingual-behavior instructions typically, and here is my model behavior config:
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
),
);
}
I get a CDbException: The table "{{candidatelang}}" for active record class "CandidateLang" cannot be found in the database.
Here is where the error triggered:
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;
I have made sure the table is there and double checked the casing and the spelling. I even tried putting different table names from the schema without any luck!! So my guess that this call is causing the error:
$model->getDbConnection()
, but i don't know Why or How to fix it??
I had the same problem and i fixed it. In the main config set tablePrefix => ''
and the problem should be fixed.