这是我的代码,当我调用此方法时发生错误并说“为 foreach() 提供的参数无效”。任何人?任何想法 ?
$state = array(
'state_status_id' => '4',
'fax_format_preference_id' => '2',
'state_reference_code' => $state_ref->reference_code,
'leap_fqdn' => $leap_fqdn ,
'description' => $state_ref->name."--".$leap_fqdn,
);
$model = new States;
$model->setAttributes($state, false);
$model->setIsNewRecord(true);
$res = $model->save();
这是堆栈信息:
public function createValidators(){
$validators=new CList;
foreach($this->rules() as $rule)
{
if(isset($rule[0],$rule[1])) // attributes, validator name
$validators->add(CValidator::createValidator($rule[1],$this,$rule[0],array_slice($rule,2)));
else
throw new CException(Yii::t('yii','{class} has an invalid validation rule. The rule must specify attributes to be validated and the validator name.',
array('{class}'=>get_class($this))));
}
return $validators;
}
这是 Rule 方法,我不知道为什么这不起作用,而其他模型和控制器中同样的东西工作正常。
public function rules()
{
//Rules for admins editing state information
if(Roles::has_permission('update','all_states'))
{
return array(
array('state_status_id, fax_format_preference_id, state_reference_code, leap_fqdn, description', 'required'),
array('state_status_id, fax_format_preference_id', 'length', 'max'=>10),
array('leap_fqdn', 'length', 'max'=>128),
array('description', 'length', 'max'=>255),
array('updated_at,default_user_role', 'safe'),
// Please remove those attributes that should not be searched.
array(' state_status_id, fax_format_preference_id, created_at, updated_at, state_reference_code, leap_fqdn, description', 'safe', 'on'=>'search'),
);
}
if(Roles::has_permission('update','state_state'))
{
return array(
array('fax_format_preference_id', 'required'),
array('fax_format_preference_id', 'length', 'max'=>10),
array('updated_at', 'safe'),
);
}
}