【问题标题】:cakephp 2.4: Add quantity with old quantity fieldcakephp 2.4:使用旧数量字段添加数量
【发布时间】:2015-01-07 19:12:26
【问题描述】:

在我的数据库表中,我有一个数量字段。我正在尝试添加将与以前一起添加的新数量。

我已经在控制器中尝试过这段代码

$this->request->data['StoreProduct']['quantity']=100+$this->request->data['StoreProduct']['quantity'];

这里的代码工作正常。但是在这里我想在 100 中放置我的旧数据。所以首先在这里我必须发送已经在数据库中的数据。如何发送这些数据以添加新数据?

我已经使用 find 方法发送了旧数据,这是代码。

$options = array('conditions' => array('StoreProduct.' . $this->StoreProduct->primaryKey => $id));
        $request= $this->StoreProduct->find('all', $options);

我已经成功看到edit.ctp中的数量了。现在我可以将此edit.ctp 发送到控制器中的编辑方法吗?

【问题讨论】:

标签: cakephp cakephp-2.4


【解决方案1】:

首先,使用

获取数据

$data = $this->StoreProduct->find('first',array('conditions'=>array('StoreProduct.id'=>$id)));

然后添加数据

$this->request->data['StoreProduct']['quantity']=$data['StoreProduct']['quantity']+$this->request->data['StoreProduct']['quantity'];

【讨论】:

  • @cms 执行此代码时遇到什么错误
  • 没有任何错误,它只取输入字段数据。添加不起作用。
  • 你确定你正确地实现了加法。您能否提供完整的操作代码。在您的问题中编辑
猜你喜欢
  • 1970-01-01
  • 2012-10-13
  • 2012-07-18
  • 2017-07-27
  • 2018-10-09
  • 2015-01-23
  • 2023-03-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多