first i must say that after a great research i found that yii is by far the best php framework under so many points of view…
but as a rookie i have an issue to solve and i did not find any solution on this forum.
I have a model that extends CActiveRecord, inside of it there is a rules() function, that works very well on the form presenting the needed validation messages. but when i extend model and in the controller i istanziate the new class instead of the old one, the validation messages on the form does not appear any more…
In the form the var_dump($model->getErrors()); give an empty array…also if the form is not submitted.
Someone else had the same issue and maybe knows how to overcome it?
Thank you for the attention and don’t esitate to ask more info if needed.
I did many time without problem. Just be sure of the functio model, as said Woil.
Here is an example of working extension I did:
<?php
class photographer extends photographerMain
{
/**
* The followings are the available columns in table 'photographer':
* @var double $ID
* @var double $user_id
* @var integer $trusted
* @var string $wm_data
* @var string $wm_mime
*/
/// used for CFileUpload
public $watermark;
/**
* Returns the static model of the specified AR class.
* @return CActiveRecord the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('watermark', 'file','allowEmpty'=>true, 'types'=>'jpeg, jpg, gif, png'),
array('trusted', 'numerical', 'integerOnly'=>true),
);
}
}
I’ve added the public static function model but the result is the same…now i go with a little bit of debug…it’s just because of my actual inexperience that i run through all this issues…
I let you know what i’ll discover, and if someone else has some idea it would be very appreciated.
Solved…as i said it was caused by my inexperience…
This is de buggy code in the controller
$model=new Player(); # Player extends User
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['User'])) # HERE THE ISSUE: the post values are passed as $_POST['Player']
{
$model->attributes=$_POST['User']; # HERE TOO
Actually it did not either try to save the model, that’s why I did not see the errors…