Issue
Am using Croogo 1.5.2 for my project. I am new to croogo System. The Croogo folder path is like this, /My_project/app/Plugin/Croogo/ Inside Plugin folder, i have created new folder named Plugin/My_folder. In that folder i have created My_controller and action add(). Also i have created the view file for add() contains the form. Now the prob am facing is, am not able to achieve model validation for my form. My_model.php contains as follow,
App::uses('AppModel', 'CroogoAppModel');
/**
* MY_model Model
*
*/
class MY_model extends AppModel {
/**
* Validation rules
*
* @var array
*/
public $validate = array(
'first_name' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Your custom message here',
)
)
);
}
The Model path is correct. But It is not validating the form fields.
If anybody knows the answer, help me. Thanks in advance.
Solution
In our Model file, no need to add the below line of code. App::uses('AppModel', 'CroogoAppModel'); Directly we can extend the AppModel.
And then, just we need to check with the method used in our controller action for model validation. It works depend on the cakephp version. Eg : $this->Model->validate(), $this->Model->invalidFields();
/**
* MY_model Model
*
*/
class MY_model extends AppModel {
/**
* Validation rules
*
* @var array
*/
public $validate = array(
'first_name' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Your custom message here',
)
)
);
}
It's working for me...
Answered By - Kavya B R Answer Checked By - Timothy Miller (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.