【问题标题】:insert query is not working in cake php插入查询在 cake php 中不起作用
【发布时间】:2012-03-01 21:16:16
【问题描述】:

这是操作网址: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";
}
?>

我想在(表名汽车)中插入数据 car_type_id 字段,但我做不到

所以请帮帮我

在此先感谢,vikas tyagi

【问题讨论】:

  • else 的错误是什么?
  • 感谢您的回复,我已经公开了,但在 car_type_id 归档中仍然是 null 值
  • Naveen 先生我没有收到任何错误,但在 car_type_id 字段中变为空值
  • 您的表单返回data[User][car_type],您正在尝试保存为汽车模型。
  • 保罗先生,我该怎么办,你能解释一下吗?

标签: php cakephp cakephp-1.3


【解决方案1】:

你可以试试这个:

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

【讨论】:

    猜你喜欢
    • 2018-11-28
    • 2012-09-14
    • 1970-01-01
    • 1970-01-01
    • 2017-05-19
    • 2013-08-17
    相关资源
    最近更新 更多