简体   繁体   中英

insert query is not working in cake php

this is action url: http://localhost/carsdirectory/users/dashboard .

dashboad.ctp (i have select filed and in this select field im fetching data from that filed car_type and table name 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 (model)

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

i want to inset data car_type_id field in (table name cars) , but im not able to do it

so plz help me

thanks in advance, vikas tyagi

您可以尝试以下方法:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM