$this->request->验证后数据更改错误cakephp
我的模型中有一些验证错误。发生错误时,我丢失了很多数据。我看到$this->request->data会像在控制器中一样被处理。但是当发生错误时,我会重定向到视图,并且我没有好的$this->request->数据来显示我的视图 请问你有什么解决办法吗 编辑:使用模型文件中的代码。我在这里添加//BUG以通知$this->data->请求未被重新设置的位置 类事件扩展了AppModel{$this->request->验证后数据更改错误cakephp,cakephp,validationerror,Cakephp,Validationerror,我的模型中有一些验证错误。发生错误时,我丢失了很多数据。我看到$this->request->data会像在控制器中一样被处理。但是当发生错误时,我会重定向到视图,并且我没有好的$this->request->数据来显示我的视图 请问你有什么解决办法吗 编辑:使用模型文件中的代码。我在这里添加//BUG以通知$this->data->请求未被重新设置的位置 类事件扩展了AppModel{ public $hasMany = 'CategoryOptionEventEvent';
public $hasMany = 'CategoryOptionEventEvent';
public $hasOne = array(
'CategoryVehicleEvent' =>
array(
//'className' => 'Event',
'joinTable' => 'category_vehicle_events',
'foreignKey' => 'id',
'associationForeignKey' => 'id',
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'with' => ''
),
);
public $validate = array(
'name' => array('rule' => 'notEmpty'),
'description' => array('rule' => 'notEmpty'),
//'date' => array('rule' => 'notEmpty'),
'hour' => array('rule' => 'notEmpty'),
'street_number' => array('rule' => 'notEmpty'),
'street_name' => array('rule' => 'notEmpty'),
'postal_code' => array('rule' => 'notEmpty'),
'city' => array('rule' => 'notEmpty'),
//BUG HERE
'vehicle_minimum' => array(
'rule1' => array(
'rule' => 'notEmpty'
),
'rule2' => array(
'rule' => array('comparisonWithField', '<=', 'vehicle_maximum'),
'message' => 'Le nombre de véhicule minimum doit être inférieur ou égal au nombre de véhicule max.'
)
),
'vehicle_maximum' => array('rule' => 'notEmpty'),
'vehicle_price' => array('rule' => 'notEmpty'),
'attendent_price' => array('rule' => 'notEmpty'),
'attendent_maximum' => array('rule' => 'notEmpty'),
'is_visible' => array('rule' => 'notEmpty'),
//Validation date
//BUG HERE
'date' => array(
'rule' => array('date', 'ymd'),
'message' => 'Entrez une date correcte !')
);
感谢您查看我的问题。我仍然有点不清楚您的要求是什么……您可以发布一个代码示例吗?如果验证失败并返回到视图,则需要重新设置$this->request->data,就像最初呈现视图时一样。如果这不是您的要求,请发布一些代码以澄清是的,我需要重新设置$this->request->data,但我不知道在哪里可以重置变量:/
if($this->Event->validates()){
}
else{
$this->request->data = $this->Event->findById($id);
}