【问题标题】:Symfony sfGuard pull a field in a specific user's profileSymfony sfGuard 拉取特定用户配置文件中的字段
【发布时间】:2012-11-02 05:06:07
【问题描述】:

我正在尝试让“产品”页面显示特定用户的简介和图片。我拥有的代码在下面,但它不断拉动当前登录的用户的简介和图片,这不是我想要的。注销后,我会立即收到 Call to a member function getBlurb() on a non-object 错误消息。有没有办法调出特定用户的“模糊”和“图片”字段?

public function executeShow(sfWebRequest $request)
  {
    $this->car = $this->getRoute()->getObject();
    $seller_id = $this->car->getSeller_id();
    $this->seller = $this->getUser()->getGuardUser($seller_id);
    $this->blurb = $this->seller->getBlurb();
    $this->picture = $this->seller->getPicture();
  }

【问题讨论】:

  • 错误很明显,因为您正在检索当前用户。但是你想从哪里获得用户?似乎不是来自会议。
  • 不,绝对不是当前用户。它将是汽车的“卖家”。我是否必须构建查询来拉取该用户?

标签: symfony-1.4 sfguard


【解决方案1】:

$this->seller 不是对象,因为$this->getUser()->getGuardUser($seller_id); 不接受任何参数,它只检索当前用户。查看sfGuardSecurityUser 处的方法定义。

你必须这样做:

教义:$this->seller = $this->car->getSeller();

推进:$this->seller = SfGuardUserPeer::retrieveByPK($seller_id);

【讨论】:

  • 这更有意义。我尝试了您建议的代码,但看起来我的 sfDoctrineGuard 插件没有 sfGuardUserPeer 类。我在网上找到了一个示例,但它扩展了BasesfGuardUserPeer,这也不存在。
  • 我发布的示例适用于 Propel。对于 Doctrine,它应该看起来像 $this->seller = Doctrine::getTable('sfGuardUser')->find($seller_id);,但我对那个 ORM 不太熟悉,所以我不确定它是否会起作用。
  • 太棒了!我查了一下,而不是find(),我不得不使用fondOneByCOLUMN,所以对我有用的行是$this->seller = Doctrine::getTable('sfGuardUser')->findOneByUsername($seller_id);谢谢你的帮助!
  • 由于Car 表中有一个seller_id 键,因此最好使用Doctrine 对象而不是创建新查询来检索卖家:$this->seller = $this->car->getSeller();
猜你喜欢
  • 2011-09-15
  • 1970-01-01
  • 2019-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多