现在的位置: 首页 > 综合 > 正文

Magento使用正规的方式输出网页(使用phtml文件输出内容)

2017年12月02日 ⁄ 综合 ⁄ 共 1692字 ⁄ 字号 评论关闭

如果你已经学会了扩展模块的基本输出方法,那么本文一定是你需要的——使用正规的方法输出网页。

假设模块为Cartz_Hotel,我们想当访问
http://localhost/magento/index.php/hotel/my/room能够输出Hello , phtml Page

 

I. 建立controllers/MyController.php内容如下:

 

 

 

 II. etc/config.xml

 

 

 

config.xml最重要的部分是
1. hotel.xml将稍后用来作为配置模块layout的文件
2. <class>Cartz_Hotel_Block</class>用来说明Block类命名规则(文件的目录位置)。

 

 

III. Block/Room.php

 

 

 

IV. 建立phtml文件
$MAGENTO_INSTALLED_DIR/app/design/<frontend>/<theme package>/<theme name>/template/hotel/room.phtml

 

 

 

 

 

V. 建立Layout文件
$MAGENTO_INSTALLED_DIR/app/design/<frontend>/<theme package>/<theme name>/layout/hotel.xml

 

 

 

 

 

当访问http://localhost/magento/index.php/hotel/my/room时,Magento自动会定位到标签<hotel_my_room>对应的block。看

 

 

 

 

 

URL  结构 http://www.yoursite.com/index.php/模块名/类名/方法名

 

 

抱歉!评论已关闭.