2011-08-22 14 views
0

我爲這個新問題提前道歉,但我一直在努力尋找正確的結果。Symfony 1.4:如何將索引操作的結果限制爲僅登錄用戶的結果

我有兩個表:

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

任何幫助深表感謝。

+0

您應該將解決方案作爲答案發布並接受它,而不是編輯問題。這樣,其他讀者就會更容易理解問題和答案。 –

+0

我試過......論壇不讓我B/C它不是8個小時。我將以答案格式重新發布。感謝您的建議和幫助。 – Patrick

回答

0

隨着這兩個受訪者我能得到它在myUser.class.php文件的另一種方法工作的幫助。以下是我得到它的工作:

在下列文件:項目>>應用>>前端>> 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()); 
} 

再次感謝兩位受訪者。

1

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

+0

感謝您的及時回覆,但是,Darhazer並沒有完全奏效。我得到這個錯誤: 調用未定義的方法myUser :: getUserId 它可能會有所幫助,提及我正在使用sfDoctrinGuardPlugin。 – Patrick

+0

我的不好,方法是getId() –

3

較短的辦法是:

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