2011-12-15 6 views
0

확인 난 내 양식을 다른 이름으로 사용하고 있기 때문에 나는 그때 그들은 예를 들어 테이블에 몇 가지 유효성 문제가 : 내가 뭔가를CakePHP의 2.0.3 모델 유효성 검사 데이터 문제

<?=$this->Form->input('name') ?> 

을 내 데이터베이스 테이블에 이 같은 이름은 xyc_name

언제나 데이터를 저장하기 전에 내가 원하는 것을 모델에 알려주고 요청 데이터로 처리 할 수있는 내용을 알려주지 만 유효성 검사를 통해 메시지를 돌려 줄지는 모릅니다.

확인 된 오류 메시지를 표시하려면 어떻게해야합니까?

이 내 코드를 아칸소 :

보기 :

<?=$this->Session->flash(); ?> 
<? 
    $subkat = ''; 
    foreach($catList as $cat) { 
     if($cat['Category']['xyc_parent']!=0) { 
      $subkat = '-'; 
     }else{ 
      $subkat = ''; 
     } 
      $options[$cat['Category']['xyc_id']] = $subkat.$cat['Category']['xyc_name']; 
    } 
?> 
<?=$this->Form->create('Product', array('type'=>'file')) ?> 

<?=$this->Form->input('category_id', array(
    'label'=>'Kategorie', 
    'options' => array($options) 
)); ?> 
<?=$this->Form->input('payment', array(
    'type'=>'radio', 
    'options' => array(1=>'PayPal',2=>'Überweisung',3=>'Barzahlung',4=>'Abholung') 
)); ?> 
<?=$this->Form->input('Product.name', array('label'=>'Produktname')); ?> 
<label for="descr">Beschreibung</label><?=$this->Form->textarea('Product.description', array('id'=>'descr')); ?> 
<?=$this->Form->input('Product.price', array('label'=>'Preis von')) ?> 
<?=$this->Form->input('Product.price_2', array('label'=>'bis')) ?> 
<?=$this->Form->input('Product.quantity', array('label'=>'Anzahl der Artikel')) ?> 
<?=$this->Form->input('Product.quantity_price', array('label'=>'Gesamtmengenpreis von')) ?> 
<?=$this->Form->input('Product.quantity_price_2', array('label'=>'bis')) ?> 
<?=$this->Form->input('Product.uvp', array('label'=>'UVP')) ?> 
<?=$this->Form->input('Product.shipment',array('label'=>'Versandart')); ?> 
<?=$this->Form->input('Product.shipmentprice',array('label'=>'Versandpreis')); ?> 
<?=$this->Form->input('Product.articelcondition',array('label'=>'Artikelzustand')); ?> 

<?=$this->Form->end(__('Senden')); ?> 

컨트롤러 :

<?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', 

      ); 


    } 
?> 

답변

0

확인. 왜냐하면 modul은 컨트롤러에서 설정 한 데이터의 유효성을 검사하고 설정 한 데이터로 출력을하고 양식에 설정된 값을 출력하지 않기 때문입니다.

그리고 메시지를 출력하기위한 입력의 Formhelper는 아무런 효과가 없습니다. 당신은 그것을 정의해야합니다. 이 같은

: 당신은 당신이

의 유효성을 확인하는 모델에 넣어 메시지를 가지고 다음
<? 
if ($this->Form->isFieldError('prefix_price')) { 
    echo $this->Form->error('prefix_price'); 
} 
?> 
<?=$this->Form->input('Product.price', array('label'=>'Preis von')) ?>