2012-03-01 96 views
0

這是動作url:http://localhost/carsdirectory/users/dashboard插入查詢不在蛋糕php

dashboad.ctp(我有選擇日提交併在此選擇字段IM取出從該日提交car_type和表名car_types數據)

<?php echo $this->Form->create('User', array('type' => 'file', 'action' => 'dashboard')); ?> 

    <label class="ls-details-label">Type</label> 
    <div class="ls-details-box"> 
     <?php 
      foreach ($car_types as $car_type) 
      { 
       $car_type_new[$car_type['Car_type']['id']]= 
             $car_type['Car_type']['car_type']; 
      } 
      echo $this->Form->input('car_type', 
            array( 'label'=>false, 
              'options'=>$car_type_new, 
              'empty'=>' Select ', 
              'class'=>'styledselect_form_1')); 
     ?> 
    </div> 
<?php echo $this->Form->end(array('label' => 'Submit', 
            'name' => 'Submit',  
            'div' => array('class' => 'ls-submit')));?> 

users_controller.php中(控制器)

class UsersController extends AppController{ 

    var $name = "Users"; 

    public function dashboard(){ 

     $this->loadModel('Car_type'); // your Model name => Car_type  
     $this->set('car_types', $this->Car_type->find('all')); 

     if(!empty($this->data)) 
     { 

     $this->loadModel('Car'); 

     if($this->Car->save($this->data)) 
     { 
      $this->Session->setFlash('Detail has Been Saved'); 

      $this->redirect(array('action'=>'dashboard')); 

     } 
     else 
     { 
      $this->Session->setFlash('Detail could not save'); 

     } 

    } 

} 

車.PHP(模型)

<?php 
class Car extends appModel{ 
    var $name = "Car"; 
} 
?> 

我想數據的插圖中(表car_type_id字段命名汽車),但我不是能夠做到這一點

所以plz幫助我

在此先感謝,維卡斯TYAGI

+1

不要使用VAR。使用公共。 – cwallenpoole 2012-03-01 12:46:40

+0

錯誤是什麼去'else'? – 2012-03-01 12:49:10

+0

感謝您的回覆,我已經公開,但仍然在空值Car_type_id提交 – 2012-03-01 12:52:22

回答

1

你可以試試這個:

echo $this->Form->input('Car.car_type_id', array(...)); 
+0

感謝Paulo Rodrigues你r grt。它爲我工作。 – 2012-03-01 13:22:47