我使用了这里建议的片段
在 Magento 之外显示一个块。
这是我的代码:
Mage::getSingleton('core/session', array('name'=>'frontend'));
$layout = Mage::app()->getLayout();
$layout->getUpdate()
->addHandle('default')
->load();
$layout->generateXml()
->generateBlocks();
$header = $layout->getBlock('header')->toHtml();
echo $header;
标题已打印,但 topLinks 与 Magento 中显示的不同。
更重要的是,html 略有不同(缺少一些 div)。
这是我的 XML 布局:
<block type="page/html_header" name="header" as="header">
<block type="core/text_list" name="top.menu" as="topMenu" translate="label">
<label>Navigation Bar</label>
</block>
<block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
<block type="page/template_links" name="top.links" as="topLinks"/>
<block type="page/html_wrapper" name="top.bar" as="topBar" translate="label">
<label>Breadcrumbs</label>
<action method="setElementClass"><value>top-bar</value></action>
<block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs"/>
</block>
<block type="page/html_wrapper" name="top.container" as="topContainer" translate="label">
<label>Page Header</label>
<action method="setElementClass"><value>top-container</value></action>
</block>
</block>
怎么了?
更新
感谢 Alan Storm 的建议,现在我知道错误是没有设置正确的句柄。
我需要将 customer_logged_in 或 customer_logged_out 添加到 $layout。
我试过了
Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton('customer/session', array('name'=>'frontend'));
$login_status = '';
if($session->isLoggedIn()){
$login_status = 'customer_logged_in';
} else {
$login_status = 'customer_logged_out';
}
但是我的用户结果即使在登录时也总是注销。
我错过了什么?