2013-02-13 59 views
0
// Include Magento application 
require_once ("../app/Mage.php"); 
umask(0); 

// Initialize Magento 
Mage::app("default"); 

// Load the session 
// This has to be done before getLayout() below or the blocks won't see the session 
$session Mage::getSingleton("core/session", array("name" => 'frontend')); 

// Get the primary layout 
global $mageLayout; 
$mageLayout = Mage::app()->getLayout(); 

// Set the layout XML to look for default and wordpress 
$mageLayout->getUpdate() 
    ->addHandle('default') 
    ->addHandle('customer_logged_in') 
    ->load(); 

(我知道你不應該設置customer_logged_in處理所有的時間。通過$會話級> isLoggedIn()我可以動態地做到這一點。我有一個更大的問題。)customer_logged_in手柄不會添加到佈局時,自舉

我已成功地能夠使用此代碼設置其他句柄。 (例如,我有一個名爲'wordpress'的句柄,用於更改加載到WordPress中的塊。)但是,手動設置customer_logged_in不起作用。

爲什麼要手動設置它?因爲controller_action_layout_load_before的客戶模塊的觀察者從不觸發。我已經想通過使用code suggested elsewhere on stackoverflow來派發觀察者,但是觀察者代碼失敗,因爲$ observer-> getEvent() - > getLayout()返回null。

所以我的問題是,儘管我可以在我的塊的phtml文件中直接訪問會話,並且使用PHP執行邏輯,但我無法利用佈局XML中存在的任何登錄/註銷邏輯因爲它們依賴於正在設置的customer_logged_in句柄。

我不知道爲什麼我創建的wordpress句柄可以正確設置,但忽略了customer_logged_in句柄。 (as customer_logged_out。)

任何人都可以幫忙嗎?

回答

1

正在添加它,但句柄中的內容完全不可能呈現。

+0

在Magento中呈現的相同塊包括這個句柄的內容。 (具體來說,客戶模塊添加到top.links塊中的鏈接。)您是否有任何建議,以瞭解在Magento之外加載時爲什麼不顯示? (我正在渲染標題塊,包括其他鏈接在內的所有其他子項都正確渲染。) 謝謝你的時間。 – 2013-02-13 04:25:40