Hello folks. I'm looking now at the code I've written and I simply don't figure out why this form doesn't ->validate():
class RbacCreateOperationForm extends CFormModel {
public $name;
public $description;
public $bizRule;
public $data;
public $type=0;
public $friendlyName='Operation';
public function rules() {
return array(
array('name, description','required'),
array('name','checkName')
);
}
public function attributeLabels() {
return array('bizRule' => 'Business rule');
}
public function checkName($attribute,$params) {
if(AuthItem::model()->findByPk($this->name)) {
$this->addError('name',$this->friendlyName.' already exists');
}
}
public function safeAttributes() {
return array(
'name','description','bizrule','data'
);
}
protected function beforeValidate($scenario) {
}
protected function afterValidate($scenario) {
if(empty($this->bizRule)) {
$this->bizRule = NULL;
}
if(empty($this->data)) {
$this->data = NULL;
}
}
}
It did work earlier, but I've made some "fundamental changes" to the entire code base, so I really can't remember where are the differences between "before" and "after". However I simply don't see any mistake in the form.
Here is how I use it:
public function actionIndex()
{
$auth = Yii::app()->authManager;
$operationsForm = new RbacCreateOperationForm;
$tasksForm = new RbacCreateTaskForm;
$rolesForm = new RbacCreateRoleForm;
if(isset($_POST['RbacCreateOperationForm'])) {
$operationsForm->attributes = $_POST['RbacCreateOperationForm'];
//throw new Exception(var_export($operationsForm,TRUE));
//throw new Exception(var_export($_POST['RbacCreateOperationForm'],TRUE));
if($operationsForm->validate()) {
throw new Exception(print_r($operationsForm,TRUE));
$newVals = $form->getAttributes();
$auth->createOperation($newVals['name'],$newVals['description'],$newVals['bizRule'],$newVals['data']);
}
}
$this->render('index',array(
'operationsForm' => $this->renderPartial('operationsform',array('form' => $operationsForm),TRUE),
'operations' => $auth->getOperations(),
'tasksForm' => $this->renderPartial('tasksform',array('form' => $tasksForm),TRUE),
'tasks' => $auth->getTasks(),
'rolesForm' => $this->renderPartial('rolesform',array('form' => $rolesForm),TRUE),
'roles' => $auth->getRoles()
));
}
Any idea?