0

この初心者の質問を前もってお詫びしますが、正しい結果を得るための適切な方法に苦労しています。

私は2つのテーブルを持っています:

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();
}

次のファイル: project>>apps>>frontend>>modules>>recipe>>actions>>actions.class.php

executeIndex アクションを次のように修正しました。

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

両回答者に改めて感謝いたします。

于 2011-08-23T12:58:47.413 に答える