李老师,帮忙Thinkphp获取表单的问题
ProductAction.class.php中的代码
<?php
class ProductAction extends Action{
//获取客户明细
public function index(){
$data=D('Client');
$list=$data->select();
$this->assign('data',$list);
$this->display();
}
//添加产品
public function add(){
$data=D('Product');
if($data->create()){
if($data->add()){
$this->success('添加成功');
}else{
$this->error('添加失败');
}
}else{
$this->error($data->getError());
}
}
}
?>
提交表单
<form action="__URL__/add" method="post">
<table width="400" border="1">
<tr>
<td width="80">请选择客户</td>
<td width="80">
<select>
<option>请选择</option>
<volist name="data" id="vo">
<option value="{$vo['id']}">{$vo['name']}</option>
</volist>
</select>
</td>
</tr>
<tr>
<td width="80">产品名称</td>
<td><input type="text" name="name"/></td>
</tr>
<tr>
<td width="80"> </td>
<td><input type="submit" value="添加"/></td>
</tr>
</table>
</form>
说明:Product表中有三个字段id,cid,name,其中cid是外键,索引Client表中的id值,现在这样添加是没问题的,但是添加后Product表中中的cid全都是0,没有获取到,试了N多种方法都不行 .
麻烦老师指点一下看我那没做好,谢谢!
<?php
class ProductAction extends Action{
//获取客户明细
public function index(){
$data=D('Client');
$list=$data->select();
$this->assign('data',$list);
$this->display();
}
//添加产品
public function add(){
$data=D('Product');
if($data->create()){
if($data->add()){
$this->success('添加成功');
}else{
$this->error('添加失败');
}
}else{
$this->error($data->getError());
}
}
}
?>
提交表单
<form action="__URL__/add" method="post">
<table width="400" border="1">
<tr>
<td width="80">请选择客户</td>
<td width="80">
<select>
<option>请选择</option>
<volist name="data" id="vo">
<option value="{$vo['id']}">{$vo['name']}</option>
</volist>
</select>
</td>
</tr>
<tr>
<td width="80">产品名称</td>
<td><input type="text" name="name"/></td>
</tr>
<tr>
<td width="80"> </td>
<td><input type="submit" value="添加"/></td>
</tr>
</table>
</form>
说明:Product表中有三个字段id,cid,name,其中cid是外键,索引Client表中的id值,现在这样添加是没问题的,但是添加后Product表中中的cid全都是0,没有获取到,试了N多种方法都不行 .
麻烦老师指点一下看我那没做好,谢谢!
作者: hygzs 发布时间: 2011-07-03
补充一下,Model中是个空的
作者: hygzs 发布时间: 2011-07-03