通過 http://localhost/magento/index.php /customer/account/create/ 分析Magento調(diào)用該頁面的過程
?
1. URL中的customer表明當(dāng)前訪問的模塊 是customer ,自動定位到: app/code/core/Mage/Customer
?
2. URL中的account 表明當(dāng)前訪問的控制器文件 為 AccountController.php? app/code/core/Mage/Customer/controllers/AccountController.php
?
3.URL中的create表明當(dāng)前訪問的php方法是 createAction() ,該方法在文件app/code/core/Mage/Customer/controllers/AccountController.php
?
4. createAction()裝載目錄 /app/design/frontend/default/default/layout/ 下名字和模塊名相同的 layout文件,名字為customer.xml。然后尋找名字為 <customer_account_create> 的標(biāo)簽,Xml代碼:
<customer_account_create> <!– Mage_Customer –> <remove name=”right”/> <remove name=”left”/> <reference name=”root”> <action method=”setTemplate”> <template>/page/1column.phtml</template> </action> </reference> <reference name=”content”> <block type=”customer/form_register” name=”customer_form_register” template=”customer/form/register.phtml”/> </reference> </customer_account_create>?
<reference name=”root”> 用來說明你要使用的布局文件。
<reference name=”content”>下的block就是你定義的block
?
上面的block是默認(rèn)定義,block類文件可以由customer/form_register推測出來: app/code/core/Mage/Customer/Block /Form/Register.php
?
template?屬推導(dǎo)出相應(yīng)的模板文件為:? app/design/frontend/default/default/template/customer/form/register.phtml
?
template之于block猶如jsp之于javabean. 通過這樣的配置block和template就聯(lián)系起來了。可以在template文件中使用$this來訪問block類的方法。
?
下面我們實(shí)現(xiàn)一個(gè)新的block應(yīng)用
?
1. 定義一個(gè)新的block文件: app/code/core/Mage/Customer/Block/Form/Register1.php
class Mage_Customer_Block_Form_Register1 extends Mage_Directory_Block_Data{ public function getHello(){ return "Hello Block"; } }??
2. 定義template文件: app\design\frontend\default\default\template\customer\form\register1.phtml
<?php echo $this->getHello(); ?>??
3. 修改customer.xml配置將Xml代碼 ?
<block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml"/>??
修改為Xml代碼 ?
<block type="customer/form_register1" name="customer_form_register1" template="customer/form/register1.phtml"/>??
重新訪問該url,不出意外你應(yīng)該可以看到下面的結(jié)果
?
?
?
轉(zhuǎn)載:http://www.beijibear.com/index.php?aid=546
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
