该validates
方法可以验证用户定义的数组吗?例如:
模型:
App::uses('AppModel', 'Model');
class Recipe extends AppModel {
public $validate = array(
'price' => 'numeric'
);
}
在控制器中:
App::uses('AppController', 'Controller');
class RecipesController extends AppController {
public function add() {
if($this->request->is('post') && $this->request->data){
$data = array('price' => $this->request->data['myprice']);
$this->Reservation->validates($data); //validate the $data array
}
else{
throw new NotFoundException();
}
}
}