0
所以我有一個插件可以根據用戶的id爲我生成信息。在用戶會話中存儲Doctrine記錄
這發生在插件的模塊「基音」:
public function executeIndex(sfWebRequest $request)
{
$unique_id = $request->getParameter('unique_id');
$this->user = UserTable::getInstance()->getByToken($unique_id);
$this->forward404Unless($this->user);
$this->iplocation=new IPLocation();
$qualified_offers = new QualifiedOffers();
$this->creatives = $qualified_offers->applicableTo($this->user);
$this->match_type = UserDemoTable::getInstance()->getValue($this->user->id, 'match');
// Put the applicable creatives into the session for later use
$userCreatives = $this->creatives;
$this->getUser()->setAttribute('userCreatives', $userCreatives);
}
然後我打電話對後續模板屬性(在調用不同的動作「家」在不同的模塊):
public function executePage(sfWebRequest $request)
{
$template = $this->findTemplate($request->getParameter('view'), $this->getUser()->getCulture());
$this->forward404Unless($template);
$this->setTemplate($template);
// Grab the creatives applicable to the user
$userCreatives = $this->getUser()->getAttribute('userCreatives');
}
不幸的是它根本不起作用。
如果我嘗試從這兒$創意最初產生的作用:
$this->getUser()->setAttribute('userCreatives', $userCreatives);
$foo = $this->getUser()->getAttribute('userCreatives');
// Yee haw
print_r($foo);
我遇到了巨大的成功。我基本上是這樣做的,只能從兩個不同的控制器。這不應該是不相關的,因爲我已經將'userCreatives'添加到用戶的會話?
它應該工作。你打電話給$ this-> getUser() - > getAttributeHolder() - > clear()之間的任何機會? – Tom 2011-05-28 00:24:04
@Tom在整個應用程序的任何地方都不會調用它。 – 2011-05-28 00:26:26
嗯......我會檢查以確保setAttribute()在getAttribute()之前肯定會被調用,而且我也會嘗試傳遞一個簡單的變量來測試。看起來你正在傳遞數組,儘管它應該可以工作。 Var_dumping getAttributeHolder也將顯示正在存儲的內容。 – Tom 2011-05-28 00:34:31