Yii架構改動資料類型
來源:互聯網
上載者:User
Yii架構更改資料類型
之前資料庫有個欄位是數值型,我用YII的工具GII把它產生,model,conttroler,view等層。後來由於項需求,要把數值改為字串,於是我就把資料庫的數值型改為字元型(char型)。然後把model層的 rules()方法下的數組:array('AA,BB, ', 'numerical'),
改為:
array('AA,BB','length','max'=>20),
最後我輸入字元提效資料時,出現如下的錯誤:
CDbException
列名必須是一個字串或者數組
D:\web_root\rd1039b\framework\db\schema\CDbCommandBuilder.php(701)
689 }
690 if(count($values)===1)
691 {
692 $entries=array();
693 foreach($values[0] as $name=>$value)
694 $entries[]=$prefix.$table->columns[$name]->rawName.($value===null?' IS NULL':'='.$value);
695 return implode(' AND ',$entries);
696 }
697
698 return $this->createCompositeInCondition($table,$values,$prefix);
699 }
700 else
701 throw new CDbException(Yii::t('yii','Column name must be either a string or an array.'));
702 }
......
.......
......
.....
......
CActiveRecord->save()
249 }
250
251
252 if (Yii::app()->user->ROLE==STUDY_USER_ROLE_PI){
253 $model->ENTRY2WHO= Yii::app()->user->USERNAME;
254 if ($model-> save())
255 {
256 if($SORT!=3){
257 $this->ToDo($Name,$MH1,$keyid);
258 }
259 else
.........
..........
........
.......
.
請問高手,這是什麼原因呀?請幫忙,謝謝啊!!
------解決方案--------------------
690 if(count($values)===1) 這裡 $values 就是 array('AA,BB','length','max'=>20), 嗎? 如果是 , 那麼count($values)===1 是 false 吧
------解決方案--------------------
無法查證具體的錯誤。
你可以去掉rules()。在試試,可不可以。如果可以用, 說明是你的rules()方法有問題。如果不可以用,說明是別的地方寫的不對。
rules規則簡單例子
public function rules()
{
return array(
array('name,email', 'length','max'=>6),
);
}
這是具體的規則列表
http://blog.csdn.net/mengxiangbaidu/article/details/7002850