[英]insert query is not working in cake php
this is action url: http://localhost/carsdirectory/users/dashboard
. 这是操作网址:
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) 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) 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 (model) car.php(模型)
<?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 我想在(表名cars)中插入数据car_type_id字段,但是我无法做到这一点
so plz help me 所以请帮我
thanks in advance, vikas tyagi 在此先感谢,vikas柳枝
您可以尝试以下方法:
echo $this->Form->input('Car.car_type_id', array(...));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.