magento-----(一)前后台url的区别分析----(二)模块的执行过程分析

本来想写成2篇,可是csdn对新号有限制,一天最多五篇,所以就把两篇写一块了!

magento-----(一)前后台url的区别分析:

前序:
在写模块的书写过程,一下子蹦出来一个问题,前台和后台是通过什么方式辨别url为前台和

后台的url??
刚发现的:关于magento前后台的URL,也就是为什么这个url访问后台,不访问前台的问题:
观察后台的url:
http://www.g4qq.com/index.php/profile/adminhtml_profile/testimonials/key/40f2065b0

5fb5f19df4d5446637ffa4f/

前台的url:
http://www.g4qq.com/customer/account/login/
可以得出:后台的url带有个key值,而且每个都带,我现在还找不出来它的根源,也就是它怎

么判断的,我只能猜了,我猜的是:在后台定义一个连接的时候(如:cms-page,一般在

system.xml 文件中注册),magento就把这个连接,生成一个对应的key,然后表明这个是后

台的,design对应的是adminhtml下的,而不是frontend,故只要在adminhtml中定义了,如:

 <adminhtml>
  <menu>
   <cms>
    <children>
     <news module="profile">
      <title>News</title>
      <sort_order>60</sort_order>

      <action>profile/adminhtml_profile/news</action>
     </news>
    </children>
   </cms>
  </menu>
  </adminhtml>

在菜单cms下面会生成一个news的菜单子项,

href="index.php/profile/adminhtml_profile/news/key/f349r4rifei",key值,我认为是在后台列表中的编号识别!

标注这个链接为后台链接,使用的后台界面要使用

app/design/adminhtml/default/default/layout,加载里面的xml文件,

后台的配置:<menu>等(从标签<adminhtml>中找)
(后台的一些东西的添加,不必和前台一样重写,可以通过配置方法添加,就像menu从一个数

组里面读取值差不多,然后显示出来)
也就是点击他的时候,会去找controler文件profile/adminhtml/profile.php 执行

newsAction方法,

例如:
<adminhtml>
 <layout>
            <updates>
                <profile>
                    <file>profile.xml</file>
                </profile>
            </updates>
        </layout>
</adminhtml>
就是加载app/design/adminhtml/default/default/layout/profile.xml文件。

说明的是:在菜单栏加一个子菜单,子菜单对用的url就会生成对用的key值,点击后访问的layout为adminhtml下面的layout

剩下的配置,前后台没大有什么区别了!!

 

----(二)模块的执行过程分析

 

 

1
在app/etc/modules/RichardMason_Profile.xml里面定义
<?xml version="1.0"?>
<config>
 <modules>
  <RichardMason_Profile>
   <active>true</active>
   <codePool>community</codePool>
  </RichardMason_Profile>
 </modules>
</config>
1.1,模块定义:
模块名:RichardMason_profile,
active:状态是否为激活状态。


codePool模块代码放的位置。本位置为community。
2
到community里面定义模块
在community下面建立RichardMason/profile/
然后再profile下面建立一些列的子文件夹。
Block ,controllers ,etc,Helper,Model,sql
3
在etc下面建立config.xml文件,改文件为配置文件,下面解析一下这个文件:
<config></config>:
里面定义
3.1
<modules></modules>
里面的模块名和文件路径对应,具体为什么要对应我也说不上来。譬如:

<RichardMason_Profile>
3.2
<frontend></frontend>
就是design那一块的定义
3.2.1<routers>
定义<frontname>

3.2.2<layout>加载layout.xml文件
3.3<admin>
<routers>
3.4
<adminhtml>
配置后台节点,该块一旦配置,,
譬如<action>
<adminhtml>
<menu>
<cms>
<children>
<news module="profile">
<action>profile/adminhtml_profile/news</action>
</news>
3.4.1
3.4.1.1
改块就会在cms下面生成菜单,而且生成的带有key的链接,用来表示该链接为后台链接。
3.4.1.2
访问的layout为adminhtml下面的,在layout的handle:<profile_adminhtml_profile_news>
3.4.2
<adminhtml>
  <layout>
            <updates>
                <profile>
                    <file>profile.xml</file>
                </profile>
            </updates>
        </layout>
指定
资源定义:
<adminhtml>
   <acl>
       <resources>
    <all>
  <title>Allow Everything</title>
    </all>
    <admin>
       <children>
  <RichardMason_Profile>
     <title>Profile Module</title>
     <sort_order>10</sort_order>
  </RichardMason_Profile>
       </children>
    </admin>
 </resources>
    </acl>

 

 


资源的定义方法
1>也就是说在adminhtml中药定义显示部分(菜单部分),用于产生后台链接,指定action。

进而用于后台显示的layouthandle。
2>update用于显示的layout中的xml文件。
3>资源权限定义。
3.4
<global>
为什么叫global呢?因为前台界面和后台界面都可以使用这里德资源,一般model,helper,

resources,block都在这里定义。

3----小结:这里定义module,frontend,admin,adminhtml,global等
module定义模块名称
frontend定义frontname,layout
admin定义frontname,对这块的认识我还是有点模糊,先这样吧。
<adminhtml>,定义后台显示部分,如<menu>,layout,<acl>权限等
global定义helpers,helpers,blocks等。
关于<models>,<helpers>,<blocks>等在以后介绍,先往下走。

4
现在到后台,应该可以看到cms下面的news显示出来了,但是点进去是什么也没有的
因为现在还没有写controler类

在前面:
<cms>
 <children>
  <news module="profile">
   <title>News</title>
   <sort_order>60</sort_order>
   <action>profile/adminhtml_profile/news</action>
  </news>
 </children>
所以路径为:RichardMason_Profile_Adminhtml_ProfileController
RichardMason_Profile_Adminhtml_ProfileController extends

Mage_Adminhtml_Controller_action
编写newsaction方法。

public function newsAction(){
  $this->loadLayout()->renderLayout();
 }
读取layout里面的<default> </default>以及<profile_adminhtml_profile_news>这个handle

里面的block。
template里面的文件读取type中的信息,生成页面
生成页面。。。。。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值