我想从帖子中获取数据,然后在另一个模型中检查它 这是我的模型
table Goods :
id,
goods_plu
table Transaction :
id,
transaction_plu
如果我想添加交易并获取 plu,则检查是否
if($trans_plu == $goods_plu )
如果 cargo 表中存在 trans_plu 数据将保存在数据库中
这是我的表格
<?php echo $this->Form->create('Transaction'); ?>
<input type="text" name="trans_plu">
<?php echo $this->Form->button('Save'); ?>
<?php echo $this->Form->end(); ?>
提前致谢!
最佳答案
你在TransactionsController中进行检查,你可以发现trans_plu是否在goods表中。
class TransactionsController extends AppController{
public $uses = array('Transaction', 'Goods');
public function add(){
if(!empty($this->data){
$goodsCount = $this->Goods->read('goods_plu', $this->data['Transaction']['trans_plu']);
if(!is_null($goodsCount)){
$this->Transaction->save($this->data);
}
}
}
}
让我知道进展如何
关于php - CakePHP 获取表单值并检查数据库(如果存在),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21618706/