Validation CakePHP 2.0.3模型验证数据问题
好的,我有一些验证问题,因为我在表格中使用了其他名称,它们在表格中作为示例:Validation CakePHP 2.0.3模型验证数据问题,validation,cakephp-2.0,cakephp-model,Validation,Cakephp 2.0,Cakephp Model,好的,我有一些验证问题,因为我在表格中使用了其他名称,它们在表格中作为示例: <?=$this->Form->input('name') ?> 控制器: <?php $this->Product->create(); $this->Product->set(array( 'fatcms_category_id' => $this->request->data[
<?=$this->Form->input('name') ?>
控制器:
<?php
$this->Product->create();
$this->Product->set(array(
'fatcms_category_id' => $this->request->data['Product']['category_id'],
$this->userPrefix.'user_id' => $this->userLoggedIn['fatcms_auth_user_id'],
$this->productPrefix.'name' => $this->request->data['Product']['name'],
$this->productPrefix.'payment' => $this->request->data['Product']['payment'],
$this->productPrefix.'description' => $this->request->data['Product']['description'],
$this->productPrefix.'price' => $this->request->data['Product']['price'],
$this->productPrefix.'price_2' => $this->request->data['Product']['price_2'],
$this->productPrefix.'quantity' => $this->request->data['Product']['quantity'],
$this->productPrefix.'quantity_price' => $this->request->data['Product']['quantity_price'],
$this->productPrefix.'quantity_price_2' => $this->request->data['Product']['quantity_price_2'],
$this->productPrefix.'shipment' => $this->request->data['Product']['shipment'],
$this->productPrefix.'shipmentprice' => $this->request->data['Product']['shipmentprice'],
$this->productPrefix.'articelcondition' => $this->request->data['Product']['articelcondition'],
$this->productPrefix.'created' => date('Y-m-d H:i:s'),
$this->productPrefix.'uvp' => $this->request->data['Product']['uvp']
));
if($this->Product->save()) {
//CakeSession::write('productid', $this->Product->id);
$this->redirect('/products/addimg/'.$this->Product->id);
}
?>
型号:
<?php
class Product extends AppModel {
public $name = 'Product';
public $useTable = 'product';
public $primaryKey = 'xyc_id';
public $hasMany = array('Productimage'=>array(
'className'=>'Productimage',
'foreignKey'=>'xyc_id'
));
public $validate = array(
'xyc_name' => array(
'rule'=>'notEmpty',
'message'=>'test'
),
'xyc__description' => 'notEmpty',
'xyc_uvp' => 'notEmpty',
'xyc_price' => 'notEmpty',
'xyc_price_2' => 'notEmpty',
'xyc_quantity_price_1' => 'notEmpty',
'xyc_quantity_price_2' => 'notEmpty',
'xyc_payment' => 'notEmpty',
'xyc_shipment' => 'notEmpty',
'xyc_shipmentprice' => 'notEmpty',
'xyc_articelcondition' => 'notEmpty',
);
}
?>
好的,我找到了解决办法。因为模块验证控制器中设置的数据,并使用设置的数据而不是表单中设置的值进行输出 因此,将信息输出的输入形式助手没有任何效果。因此你必须定义它 像这样:
<?
if ($this->Form->isFieldError('prefix_price')) {
echo $this->Form->error('prefix_price');
}
?>
<?=$this->Form->input('Product.price', array('label'=>'Preis von')) ?>
然后你得到了一条消息,你把它放在你的模型中进行验证
<?
if ($this->Form->isFieldError('prefix_price')) {
echo $this->Form->error('prefix_price');
}
?>
<?=$this->Form->input('Product.price', array('label'=>'Preis von')) ?>