Symfony1 Symfony 1.4:如何将索引操作的结果限制为仅登录用户的结果

Symfony1 Symfony 1.4:如何将索引操作的结果限制为仅登录用户的结果,symfony1,doctrine,dql,Symfony1,Doctrine,Dql,我为这个新问题提前道歉,但我一直在努力寻找正确的方法来获得正确的结果 我有两张桌子: sf_guard_user: Columns id name recipe: Columns: id: user_id: name: relations: sf-guard_user: { local: user_id, foreign: id; foreign_alias: recipes } 配方模块,索引成功: 在此表单中,我希望将结果限制为

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

我有两张桌子:

sf_guard_user:
  Columns
    id
    name

recipe:
  Columns:
    id:
    user_id:
    name:
  relations:
    sf-guard_user: { local: user_id, foreign: id; foreign_alias: recipes }
配方模块,索引成功: 在此表单中,我希望将结果限制为仅登录用户

以下是我的recipe 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();
}

非常感谢您的帮助。

->where('user\u id=?',$this->getUser()->getGuardUser()->getId();)

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

较短的方法是:

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

较短的方法是:

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

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

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

我添加了这个方法:

public function getId()
{
  return $this->getGuardUser()->getId();
}
在以下文件中:项目>>应用>>前端>>模块>>配方>>动作>>动作.class.php

我将executeIndex操作修改为:

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

再次感谢两位受访者。

在两位受访者的帮助下,我能够使用myUser.class.php文件中的另一个方法使其正常工作。下面是我如何让它工作的:

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

我添加了这个方法:

public function getId()
{
  return $this->getGuardUser()->getId();
}
在以下文件中:项目>>应用>>前端>>模块>>配方>>动作>>动作.class.php

我将executeIndex操作修改为:

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

再次感谢两位受访者。

感谢您的及时回复,但达哈泽,这并不奏效。我得到了这个错误:调用未定义的方法myUser::getUserId提到我使用的是sfDoctrinGuardPlugin可能会有所帮助。我的错,方法是getId(),感谢您的及时回复,Darhazer,但是,这并没有起到很好的作用。我得到了这个错误:调用未定义的方法myUser::getUserId提到我使用的是sfDoctrinGuardPlugin可能会有帮助。我的错,方法是getId()。你应该将解决方案作为答案发布并接受它,而不是编辑问题。这样,其他读者就更容易理解问题和答案了。我试着。。。论坛不允许我用b/c,因为还不到8个小时。我会以答案的形式重新发布。感谢您的建议和帮助。您应该将解决方案作为答案发布并接受它,而不是编辑问题。这样,其他读者就更容易理解问题和答案了。我试着。。。论坛不允许我用b/c,因为还不到8个小时。我会以答案的形式重新发布。谢谢你的建议和帮助。