i just write my first article so please tell me if i've done something wrong! My Problem: I want to validate data given by url.
../Logs/requests?from=2011-10-18T16:15:00&to=2011-10-18T16:30:00&fmt=csv
I have just find out that there is an option to validate with the rules added to the Model.
public $validate = array(
'request_id' => array(
'alphaNumeric' => array(
'rule' => 'alphaNumeric',
'required' => true,
'message' => 'Alphabets and numbers only'
),
)
);
Using "ModelName->set($params)" in the Controller and after that the "ModelName->validates()"-function should deliver the answer if its valid or not. The only differenz between my solution and the solution at http://book.cakephp.org/2.0/en/models/data-validation/validating-data-from-the-controller.html is that my controller using a couple of Models to collect the data for the response. The problem is that the "validates()"-function just return "valid" even if i put in special-characters or other stuff what should be "not valid"-signed by the model-rules. Help!
$paramsvariable to your question? You may need to add a ModelAlias key to the $params array, like this;$params = array('MyModelAlias' => $params);- thaJeztah$params = array('request_id'=>'4*G/&2')work? If not try this;$params = array('ModelName' => array('request_id'=>'4*G/&2'));. You are correct that you are able to manually 'validate' the data, without saving it, however, the model will look inside the 'params' data for a key named after the 'alias' of the model (e.g. 'ModelName') and only validate fields inside that key. If the ModelAlias key is missing, it will find no 'fields' to validate - thaJeztah