1

私は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()、しかし私はそれを修正する理由または方法がわかりませんか?

4

2 に答える 2

1

私は同じ問題を抱えていて、それを修正しました。メイン構成セットtablePrefix => ''で、問題を修正する必要があります。

于 2012-07-17T07:02:43.217 に答える
0

db次のように自動生成されたモデル変数を強制しようとしました:

    public function createLangClass() {
    if(!class_exists($this->langClassName, false)) {
        $owner_classname = get_class($this->getOwner());
        eval("class {$this->langClassName} extends CActiveRecord
        {
                  //Forcing model db variable
            self::db = Yii::app()->getDb();

            public static function model(\$className=__CLASS__)
            {
                return parent::model(\$className);
            }

            public function tableName()
            {
                return '{{{$this->langTableName}}}';
            }

            public function relations()
            {
                return array('$owner_classname' => array(self::BELONGS_TO, '$owner_classname', '{$this->langForeignKey}'));
            }

        }");
    }
} 

理由はまだわかりません!!CdbExceptionなくなったので、うまくいくようです。

しかし、Yiibase が動的に自動生成されたモデル ファイルが見つからないという新しいエラーが発生しました!! 以前は Yii で動的クラスを使用した経験がありませんでしたが、この問題は yii1.1.10 で新たに発生したものではないかと考えています。簡単な修正があればコメントしてください。そうでない場合は、新しい質問を投稿します。

于 2012-07-15T08:00:33.657 に答える