CakePHP获取表单值并检查数据库(如果存在)
我想从post中获取数据,然后在另一个模型中进行检查 这是我的模型CakePHP获取表单值并检查数据库(如果存在),php,mysql,cakephp,model,controller,Php,Mysql,Cakephp,Model,Controller,我想从post中获取数据,然后在另一个模型中进行检查 这是我的模型 table Goods : id, goods_plu table Transaction : id, transaction_plu 如果我想添加事务并获取plu,请检查 if($trans_plu == $goods_plu ) 如果商品表中存在trans_plu 数据将保存在数据库中 这是我的表格 <?php echo $this->Form->create('Transaction'); ?>
table Goods :
id,
goods_plu
table Transaction :
id,
transaction_plu
如果我想添加事务并获取plu,请检查
if($trans_plu == $goods_plu )
如果商品表中存在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(); ?>
提前谢谢 您执行签入TransactionController,您可以发现trans_plu是否在货物表中
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);
}
}
}
}
让我知道进展如何对不起,读到你的问题我感到很困惑。当使用CakePHP时,你应该遵循它的标准/惯例,例如,
Transaction
应该是Transactions
,等等。看起来你的表中有Transaction\u plu
,表格中有trans\u plu
。我不知道你具体在问什么。在有人提出答案之前,你需要用更多的代码重新表述你的问题。