0

我有一个按钮,当单击该按钮时,它将通过 +1 更新一行。

它不起作用,它只会在数据库表中更新为 1,下次我单击它时它不会变为 2,它会保持在 1。我想要它,每次单击它都会将数字增加 1。

这是模型中的功能:

class Application_Model_DbTable_Row_User extends Sayka_Db_Table_Row_Abstract
{
    public function grantDiscount()
    {
        $this->has_discount = has_discount + 1;
                // $this->has_discount++; <- not working too, only increment to 1.
        $this->save();
    }
}

控制器:

if (isset($_POST['btn_buy_now']))
{
     $user->grantDiscount();
}
4

2 回答 2

1

我自己通常不会DbTable_Row以这种方式使用该对象,但我认为您的函数应该如下所示:

<?php
class Application_Model_DbTable_Row_User extends Sayka_Db_Table_Row_Abstract
{
    public function grantDiscount()
    {
        /*row object->column->has_discount = row object->column->has_discount +1*/
        $this->has_discount = $this->has_discount + 1;

        $this->save();
        /*returning the row object may or may not be important or helpful in this case.*/
        return $this;
    }
}

请记住,save()返回插入/更新行的主键或异常。

于 2013-01-15T05:35:48.703 回答
0

Zend_Db_Table_Row_Abstract 和 Sayka_Db_Table_Row_Abstract 之间有什么区别吗?可能它取代了zend 原始的魔法方法__get 和__set。

于 2013-01-15T08:34:18.733 回答