2012-03-01 10 views
0

これはアクションURLです:http://localhost/carsdirectory/users/dashboardです。挿入クエリがケーキのPHPで動作していません

dashboad.ctp

<?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'); 

     } 

    } 

} 

車(私はその日に出願car_typeとテーブル名car_typesからデータをフェッチ提出し、この選択フィールドイムで選択しました) .php(モデル)

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

私は(テーブル内のデータにcar_type_idフィールドをはめ込みたいです

はそうPLZ、ヴィカスティアギ(Tyagi)

+1

VARを使用しないでください。パブリックを使用する。 – cwallenpoole

+0

エラーは 'else'に送られていますか? –

+0

返信ありがとう、私はpublicを行っていますが、まだcar_type_idにnull値が入っています –

答えて

1

あなたはこれを試すことが事前に私に

感謝を助ける)の車に名前を付け、しかし、私はそれを行うことができませんメートル:

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

ありがとうPaulo Rodrigues you r grt。それは私のために働いています。 –