插入查询不能在蛋糕php中工作

时间:2012-03-01 12:41:17

标签: php cakephp cakephp-1.3

这是行动网址: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(controller)

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

1 个答案:

答案 0 :(得分:1)

你可以试试这个:

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