Reputation: 357
In my app, I need to make a table(CGridView) having few columns and a column with button. When I click the button, it should perform create action on model "studentKurs". So, I pass the arguments to the table, and as I see, the function is executed. What fails is my model validation, even though I pass arguments by GET and retrieve them in the actionCreateCustom method I made and populate $model fields with them. What am I missing?
Here is the part from the table in which I create URL:
array(
'class' => 'CButtonColumn',
'template' => '{add}',
'buttons' => array(
'add' => array(
'url' => 'Yii::app()->createUrl("studentKurs/createCustom",
array(
"student_id" => $data[\'id\'],
"predmet_naziv" => $_GET[\'predmet_naziv\'],
"id_stud_prog" => $data[\'id_stud_prog\'],
"id_nivo_stud" => $data[\'id_nivo_stud\'],
"stud_god_god" => $_GET[\'stud_god_god\']
)
)',
),
),
),
Function from controller:
public function actionCreateCustom($student_id, $predmet_naziv, $id_stud_prog, $id_nivo_stud, $stud_god_god)
{
$model=new StudentKurs;
$model['predmet_naziv'] = $predmet_naziv;
$model['id_stud_prog'] = $id_stud_prog;
$model['id_nivo_stud'] = $id_nivo_stud;
$model['stud_god_god'] = $stud_god_god;
$model['student_id'] = $student_id;
$model['ocjena'] = '';
$model['polozeno'] = '';
if($model->validate())
{
echo "OK";
$this->saveModel($model);
}
else
{
echo "ERROR";
}
//$this->refresh();
}
ERROR message gets echoed on my screen. Any ideas?
Upvotes: 1
Views: 29
Reputation: 133370
You can get the validation errors this way
if ($model->validate()) {
// all inputs are valid
} else {
// validation failed: $errors is an array containing error messages
$errors = $model->errors;
var_dump($errors);
}
or (trivial way) you can comment selectively your rule for investigatin the responsable ..
Upvotes: 1