簡體   English   中英

插入查詢不適用於蛋糕PHP

[英]insert query is not working in cake php

這是操作網址: http://localhost/carsdirectory/users/dashboard

dashboad.ctp(我已選擇文件,並在此選擇字段中從該文件中提取數據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'); 

        }

    }

}

car.php(模型)

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

我想在(表名cars)中插入數據car_type_id字段,但是我無法做到這一點

所以請幫我

在此先感謝,vikas柳枝

您可以嘗試以下方法:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM