如何在magento中建立自定義頁面
老話重提,我們還是通過URL來進行分析http://<host>/<Magento虛擬目錄>/<config.xm中的frontName>/<Controller文件名去掉Controller>/<Controller文件的方法名去掉Action>
例如,我們現在想在paypal的模塊中,增加一個查看幫助的頁面。
訪問url為:
http://youip/paypal/standard/help
那么我們反向分析。根據之前的分析,我們找到控制文件
\app\code\core\Mage\Paypal\controllers\StandardController.php
在里面增加一個方法
- public function helpAction()
-
{ -
-
$this->loadLayout(); -
$this->_initLayoutMessages('paypal/session'); -
$this->renderLayout(); -
}
增加以下片段:
-
<paypal_standard_help> -
<!-- Mage_Paypal --> -
<remove name="right"/> -
<remove name="left"/> -
<reference name="root"> -
<action method="setTemplate"> -
<template>/page/1column.phtml</template> -
</action> -
</reference> -
<reference name="content"> -
<block type="paypal/standard_help" name="paypal_standard_help" template="paypal/standard/help.phtml"/> -
</reference> -
</paypal_standard_help>
- class Mage_Paypal_Block_Standard_Help extends Mage_Directory_Block_Data
- {
-
public function getHelp(){ -
return "this is paypal help file content!"; -
} - }
\app\design\frontend\default\default\template\paypal\standard\help.phtml
- <?php echo $this->getHelp(); ?>