老话重提,我们还是通过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();
- }
其中:$this->loadLayout();将载入\app\design\frontend\default\default\layout\目录下的paypal.xml
增加以下片段:- <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>
接着建立block类文件,\app\code\core\Mage\Paypal\Block\Standard\Help.php- 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(); ?>
如何在magento中建立自定义页面
原文:http://www.blogjava.net/yxhxj2006/archive/2015/02/25/423028.html