0

我提前为这个新手问题道歉,但我一直在努力寻找正确的方法来获得正确的结果。

我有两张桌子:

sf_guard_user:
  Columns
    id
    name

recipe:
  Columns:
    id:
    user_id:
    name:
  relations:
    sf-guard_user: { local: user_id, foreign: id; foreign_alias: recipes }

配方模块,indexSuccess:此表单是我想将结果限制为仅登录用户的地方。

这是我的食谱 actions.class.php 文件:

public function executeIndex(sfWebRequest $request)
{
$this->recipe = Doctrine_Core::getTable('recipe')
  ->createQuery('a')
  ->whereStatement: user_id = logged-in/posted user (this is where I'm struggling with the syntax... do I use a join statement? Or where statement?  ...I'm lost.  I can get the result I want in basic MySql, but not in DQL)
  ->execute();
}

任何帮助深表感谢。

4

3 回答 3

3

更短的方法是:

public function executeIndex(sfWebRequest $request)
{
  $this->recipes = RecipeTable::getInstance()->findByUserId($this->getUser()->getId());
}
于 2011-08-22T20:23:57.757 回答
1

->where('user_id = ?', $this->getUser()->getGuardUser()->getId(););

于 2011-08-22T20:00:08.303 回答
0

在两位受访者的帮助下,我能够使用 myUser.class.php 文件中的其他方法来使用它。这是我如何让它工作的:

在以下文件中:project>>apps>>frontend>>lib>>myUser.class.php

我添加了这个方法:

public function getId()
{
  return $this->getGuardUser()->getId();
}

并在以下文件中:项目>>应用程序>>前端>>模块>>配方>>操作>>actions.class.php

我将 executeIndex 操作修改为:

public function executeIndex(sfWebRequest $request)
{
  $this->recipes = RecipeTable::getInstance()->findByUserId($this->getUser()->getId());
}

再次感谢两位受访者。

于 2011-08-23T12:58:47.413 回答