【问题标题】:Symfony Write to sfGuard TableSymfony 写入 sfGuard 表
【发布时间】:2012-10-29 01:26:03
【问题描述】:

我知道这并不理想,但我在 sfGuard 用户表上有一些额外的字段,我想从另一个模块写入它。有一个特定的字段是一个简单的整数,但我希望每次他们执行特定任务时它都为 -1。这是我尝试过的。我没有收到错误消息,但它也没有将数字写入表中。

  public function executePublish(sfWebRequest $request)
  {
    $this->user = $this->getUser()->getGuardUser();
    $times = ($this->user->getTimes() - 1);
    $this->getUser()->getGuardUser()->setTimes($times);
  }

这是针对不同模块的“发布”操作。我做错了吗?谢谢。

【问题讨论】:

    标签: symfony-1.4 sfguard


    【解决方案1】:

    setTimes($times) 没有对数据库进行 INSERT 设置对象的所有值后,您必须调用save()方法。

    应该是这样的:

     public function executePublish(sfWebRequest $request)
      {
        $this->user = $this->getUser()->getGuardUser();
        $times = ($this->user->getTimes() - 1);
        $this->user->setTimes($times);
        $this->user->save();
      }
    

    【讨论】:

    • 效果很好。感谢那。我不知道我是怎么错过的。 :)
    猜你喜欢
    • 1970-01-01
    • 2011-10-18
    • 1970-01-01
    • 2011-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多