2013-06-20 29 views
6

我有一個要求,註銷網址必須只在我的帳戶底部可見,它的每個部分就像在「帳戶信息」,「地址簿」,「我的訂單」類似的所有。如何在我的帳戶頁面的每個部分下添加註銷URL?

Please See the sample Image 如何做到這一點?

哪裏應該寫

action method="addLink" translate="label title" module="customer"><label>Log Out</label><url helper="customer/getLogoutUrl"/><title>Log Out</title><prepare/><urlParams/><position>100</position></action> 

在我customer.xml文件。

回答

17

您可以刪除customer.xml中的'customer_logged_in'塊,然後您可以像這樣在customer.xml中添加/創建塊。

<reference name="content"> 
      <block type="page/html_wrapper" name="my.account.wrapper" translate="label"> 
       <label>My Account Wrapper</label> 
       <action method="setElementClass"><value>my-account</value></action> 
       <block type="core/template" name="logout_link" template="customer/logout_link.phtml"/> 
      </block> 
</reference> 

而且logout_link.phtml的內容會是這樣的,

<?php 
$loggedIn = $this->helper("customer")->isLoggedIn(); 
if($loggedIn == 1){ 
    echo "<a href=\"".Mage::getBaseUrl()."customer/account/logout/\" >LOGOUT</a>"; 
}else{ 
    echo "<a href=\"".Mage::getBaseUrl()."customer/account/\" >LOGIN</a>"; 
}?> 

....

+0

我跟着你的代碼。它顯示「你已經註銷並將在5秒內重定向到我們的主頁。」但它會自動將我從我的帳戶頁面重定向到主頁 – Muk

+0

哦!您必須設置不同的模板意味着您需要創建其他模板,您可以在其中打印註銷鏈接邏輯。 'customer/logout.phtml'只是一個例子。 logout.phtml將做你在你的評論中提到的 –

+0

更新我的代碼 –

6

這是更好地使用這些網址:

Mage::helper('customer')->getLogoutUrl() 
Mage::helper('customer')->getLoginUrl() 

它使用客戶幫手而不是硬編碼的URL。

相關問題