通過(guò) http://localhost/magento/index.php /customer/account/create/ 分析Magento調(diào)用該頁(yè)面的過(guò)程
?
1. URL中的customer表明當(dāng)前訪問(wèn)的模塊 是customer ,自動(dòng)定位到: app/code/core/Mage/Customer
?
2. URL中的account 表明當(dāng)前訪問(wèn)的控制器文件 為 AccountController.php? app/code/core/Mage/Customer/controllers/AccountController.php
?
3.URL中的create表明當(dāng)前訪問(wèn)的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”> 用來(lái)說(shuō)明你要使用的布局文件。
<reference name=”content”>下的block就是你定義的block
?
上面的block是默認(rèn)定義,block類(lèi)文件可以由customer/form_register推測(cè)出來(lái): 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. 通過(guò)這樣的配置block和template就聯(lián)系起來(lái)了??梢栽趖emplate文件中使用$this來(lái)訪問(wèn)block類(lèi)的方法。
?
下面我們實(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"/>??
重新訪問(wèn)該url,不出意外你應(yīng)該可以看到下面的結(jié)果
?
?
?
轉(zhuǎn)載:http://www.beijibear.com/index.php?aid=546
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

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