magento ----后台grid模块的加载 --以news插件为例个人分析(一)

2024-03-25 15:08

本文主要是介绍magento ----后台grid模块的加载 --以news插件为例个人分析(一),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 

 

 

后台grid后台加载过程

以插件news为例:

个人分析,不保证没有分析错误的地方!!

前面的菜单的生成过程就不写了。

 

1。访问地址:index.php/admin/profile/adminhtml_profile/news/

访问richardMason/profile/controllers/adminhtml/profileController.php的newsAction方法。

 

 

 

2

2.1首先构造方法,生成对象

2.2然后访问方法newsAction

 

public function newsAction(){

Mage::register('profile_category_id', RichardMason_Profile_Model_Profile::CATEGORY_NEWS);

$this->_initAction()

->renderLayout();

}

 

2.2.1RichardMason_Profile_Model_Profile::CATEGORY_NEWS

类方法,使用类变量,可以直接这样使用,在该类中定义格式如下:

  const CATEGORY_NEWS = 0;

2.2.2Mage::register,将category_news的值注册到变量profile_category_id,然后别的地方可以通过register函数直接取到。

 

2.2.3访问

 

protected function _initAction() {

$this->loadLayout()

->_setActiveMenu('profile/items')

->_addBreadcrumb(Mage::helper('adminhtml')->__('Profiles Manager'), Mage::helper('adminhtml')->__('Profile 

 

Manager'));

return $this;

方法分析:加载menu,后台页面。(也许是!),将layout加载,计算出来

然后访问newsAction方法。

2.2.4renderLayout将加载的现实出来,然后结束。

 

3

从2.2.3开始$this->loadLayout();

3.1加载layout文件。

在adminhtml/default/default/layout/profile.xml文件中。

 

<profile_adminhtml_profile_news>

        <reference name="content">

            <block type="profile/adminhtml_profile" name="profile" />

        </reference>

 

3.2<profile_adminhtml_profile_news>,这个是和访问url对应的,url为profile/adminhtml_profile/news

所以加载这个layouthandle,在此处type="profile/adminhtml_profile",因此,加载block:ichardMason/Profile/Block/Adminhtml/Profile.php

4RichardMason_Profile_Block_Adminhtml_Profile

实例化访问方法:

public function __construct()

  {

    $this->_controller = 'adminhtml_profile';

    $this->_blockGroup = 'profile';

 

    $this->_headerText = Mage::helper('profile')->getText(Mage::registry('profile_category_id'), '_headerText');

    parent::__construct();

    parent::_addButton('add', array(

'label'     => Mage::helper('profile')->getText(Mage::registry('profile_category_id'), 'New'),

'onclick'   => 'setLocation(/''.$this->getUrl('*/*/edit', array('category_id' => Mage::registry

 

('profile_category_id'))).'/')',

        'class'     => 'add',

    ));    

  }

 

4.1

$this->_controller,$this->_blockGroup,赋值,用处为加载grid.php.edit.php等,生成block用的变量,例如后面的方法

Mage_Adminhtml_Block_Widget_Grid_Container中的方法

  protected function _prepareLayout()

    {

        $this->setChild( 'grid',

            $this->getLayout()->createBlock( $this->_blockGroup.'/' . $this->_controller . '_grid',

            $this->_controller . '.grid')->setSaveParametersInSession(true) );

        return parent::_prepareLayout();

    }

生成block就是用的这个变量。

4.2从hRichardMason_Profile_Helper_Data类中的方法getText()得到这个grid的标题。--headerText

 

4.3  parent::__construct();

4.4 执行方法

 parent::_addButton('add', array(

'label'     => Mage::helper('profile')->getText(Mage::registry('profile_category_id'), 'New'),

'onclick'   => 'setLocation(/''.$this->getUrl('*/*/edit', array('category_id' => Mage::registry

 

('profile_category_id'))).'/')',

        'class'     => 'add',

    )); 

 

 

 

5  (next--4.4 执行方法)

从4.3展开 parent::__construct();

parent::__construct();

Mage_Adminhtml_Block_Widget_Grid_Container

 

 public function __construct()

    {

        parent::__construct();

 

        $this->setTemplate('widget/grid/container.phtml');

 

        $this->_addButton('add', array(

            'label'     => $this->getAddButtonLabel(),

            'onclick'   => 'setLocation(/'' . $this->getCreateUrl() .'/')',

            'class'     => 'add',

        ));

    }

 

5.1

parent::__construct();

5.2

指定template

$this->setTemplate('widget/grid/container.phtml');

5.3被4.4执行方法覆盖!

6(next--5.2----4.4 执行方法)

接着5.1

parent::__construct();

 

class Varien_Object implements ArrayAccess下面的方法

 public function __construct()

    {

        $args = func_get_args();

        if (empty($args[0])) {

            $args[0] = array();

        }

        $this->_data = $args[0];

 

        $this->_construct();

    }

 

6.1

func_get_args();

解释:

/**

 * Returns an array comprising a function's argument list

 * @link http://www.php.net/manual/en/function.func-get-args.php

 * @return array an array in which each element is a copy of the corresponding

 * member of the current user-defined function's argument list.

 */

我认为的大致意思是将url中的值拿出来,然后放入数组中,也就是$this->_data[]

因此执行到这步,可以获得url中的参数的值。

 

7(4.4 执行方法)

接5.2

$this->setTemplate('widget/grid/container.phtml');

找到这个文件:

 

<div class="content-header">

    <table cellspacing="0">

        <tr>

            <td style="<?php echo $this->getHeaderWidth() ?>"><?php echo $this->getHeaderHtml() ?></td>

            <td class="form-buttons"><?php echo $this->getButtonsHtml() ?></td>

        </tr>

    </table>

</div>

<div>

    <?php echo $this->getGridHtml() ?>

</div>

 

7.1

$this->getHeaderWidth()

路径:

Mage_Adminhtml_Block_Widget_Grid_Container

 

 public function getHeaderWidth()

    {

        return 'width:50%;';

    }

 

7.2

路径:

 

$this->getHeaderHtml()

 

Mage_Adminhtml_Block_Widget_Container

 

  public function getHeaderHtml()

    {

        return '<h3 class="' . $this->getHeaderCssClass() . '">' . $this->getHeaderText() . '</h3>';

    }

 

 

7.3

echo $this->getButtonsHtml()

Mage_Adminhtml_Block_Widget_Container

public function getButtonsHtml($area = null)

    {

        $out = '';

        foreach ($this->_buttons as $level => $buttons) {

            foreach ($buttons as $id => $data) {

                if ($area && isset($data['area']) && ($area != $data['area'])) {

                    continue;

                }

                $childId = $this->_prepareButtonBlockId($id);

                $child = $this->getChild($childId);

 

                if (!$child) {

                    $child = $this->_addButtonChildBlock($childId);

                }

                if (isset($data['name'])) {

                    $data['element_name'] = $data['name'];

                }

                $child->setData($data);

 

                $out .= $this->getChildHtml($childId);

            }

        }

        return $out;

    }

 

 

7.4  7.1,7.2,7.3都是使用系统默认函数,因此懒的话可以不研究。使用默认的就可以

7.5

<?php echo $this->getGridHtml() ?>

这个是重点。

Mage_Adminhtml_Block_Widget_Grid_Container

public function getGridHtml()

    {

        return $this->getChildHtml('grid');

    }

 

返回4.1可以看到方法

Mage_Adminhtml_Block_Widget_Grid_Container中的方法

  protected function _prepareLayout()

    {

        $this->setChild( 'grid',

            $this->getLayout()->createBlock( $this->_blockGroup.'/' . $this->_controller . '_grid',

            $this->_controller . '.grid')->setSaveParametersInSession(true) );

        return parent::_prepareLayout();

    }

生成了as =“grid”这个block,因此:得到的是RichardMason_Profile_Block_Adminhtml_Profile_Grid

 

8(4.4 执行方法)

RichardMason_Profile_Block_Adminhtml_Profile_Grid

 

 public function __construct()

    {

        parent::__construct();

        $this->setId('profileBlockGrid');

        $this->setDefaultSort('profile_id');

        $this->setDefaultDir('ASC');

    }

 

8.1为了好排序,把这个放前面吧。

给$this->_data[] 里面的数据赋值

 $this->setId('profileBlockGrid');

        $this->setDefaultSort('profile_id');

        $this->setDefaultDir('ASC');

 

8.2

 parent::__construct();

9

接着8.2

 

Mage_Adminhtml_Block_Widget_Grid

 public function __construct($attributes=array())

    {

        parent::__construct($attributes);

        $this->setTemplate('widget/grid.phtml');

        $this->setRowClickCallback('openGridRow');

        $this->_emptyText = Mage::helper('adminhtml')->__('No records found.');

    }

 

 

呵呵,又开始复杂了,不急,慢慢来

9.1

 parent::__construct($attributes);

又是这个函数,前面已做解析

Varien_Object

 public function __construct()

    {

        $args = func_get_args();

        if (empty($args[0])) {

            $args[0] = array();

        }

        $this->_data = $args[0];

 

        $this->_construct();

    }

 

9.2

 $this->setTemplate('widget/grid.phtml');

 

打开一个好大的文件,先放一边,分析下面的。

 

9.3

 $this->setRowClickCallback('openGridRow');

貌似magento里面没有这个函数,用dreamweaver全面搜索也没有搜索出来,可能是需要自己写的,就这样吧

 

9.4

$this->_emptyText = Mage::helper('adminhtml')->__('No records found.');

应该是没有数据输出的吧。

下面来分析这个$this->setTemplate('widget/grid.phtml');

10.哈哈,继续走

 

follow me

 

不喜欢费劲就不研究了吧,这个是系统的,放哪里吧。。。。。懒。。

 

 

***********************************************************************

分析一下里面的方法吧。。

11

RichardMason_Profile_Block_Adminhtml_Profile_Grid <---(type="")

default/default/template/widget/grid.phtml

里面的方法

$this->getCollection()

$this->canDisplayContainer()

$this->getGridHeader()

echo $this->getId() 

$this->getMessagesBlock()->getGroupedHtml()

$this->getPagerVisibility()

$this->getExportTypes

$this->getFilterVisibility()

$this->getPagerVisibility()

$this->getJsObjectName()

$this->getVarNamePage() 

$this->getVarNameLimit()

$this->getHtmlId()

$this->getRssLists()

$this->getExportTypes()

$this->getExportButtonHtml()

$this->getMainButtonsHtml()

$this->getExportButtonHtml()

$this->getMainButtonsHtml()

$this->getMassactionBlock()

$this->getMassactionBlockHtml() 

$this->getHeadersVisibility()

$this->getColumns()

妈的不抄了,这么多明天就分析这几个可以了

 

其实模仿

RichardMason_Profile_Block_Adminhtml_Profile_Grid把下面的函数实现了就可以了,上面的函数,默认库里有

12

protected function _prepareCollection()

protected function _prepareColumns()

protected function _afterLoadCollection()

protected function _filterStoreCondition($collection, $column)

public function getRowUrl($row)

 

 

 

 

 

 

 

 

 

 

13(next--->11,12)

4.4 执行方法

 parent::_addButton('add', array(

'label'     => Mage::helper('profile')->getText(Mage::registry('profile_category_id'), 'New'),

'onclick'   => 'setLocation(/''.$this->getUrl('*/*/edit', array('category_id' => Mage::registry

 

('profile_category_id'))).'/')',

        'class'     => 'add',

    )); 

 

13.1_addButton是一个数组,

label的值helper函数取到的,前面已经介绍

13.2

'onclick'   => 'setLocation(/''.$this->getUrl('*/*/edit', array('category_id' => Mage::registry('profile_category_id'))).'/')',

模仿他的就可以了

index.php/admin/profile/adminhtml_profile/edit/category_id/0/key/d4dce0e331b0a88fc1b1d05e672473da/

以上面的为例子*/*/edit就是profile/adminhtml_profile/edit

array('category_id' => Mage::registry('profile_category_id'))就是:/category_id/0/

ok,基本大功告成

明天分析11.12

2点44了,那就今天睡完在写。。。。。

 

 

 

 

 

 

 

这篇关于magento ----后台grid模块的加载 --以news插件为例个人分析(一)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/845380

相关文章

Python中的Walrus运算符分析示例详解

《Python中的Walrus运算符分析示例详解》Python中的Walrus运算符(:=)是Python3.8引入的一个新特性,允许在表达式中同时赋值和返回值,它的核心作用是减少重复计算,提升代码简... 目录1. 在循环中避免重复计算2. 在条件判断中同时赋值变量3. 在列表推导式或字典推导式中简化逻辑

SpringBoot中配置文件的加载顺序解读

《SpringBoot中配置文件的加载顺序解读》:本文主要介绍SpringBoot中配置文件的加载顺序,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录SpringBoot配置文件的加载顺序1、命令⾏参数2、Java系统属性3、操作系统环境变量5、项目【外部】的ap

Python的time模块一些常用功能(各种与时间相关的函数)

《Python的time模块一些常用功能(各种与时间相关的函数)》Python的time模块提供了各种与时间相关的函数,包括获取当前时间、处理时间间隔、执行时间测量等,:本文主要介绍Python的... 目录1. 获取当前时间2. 时间格式化3. 延时执行4. 时间戳运算5. 计算代码执行时间6. 转换为指

Python正则表达式语法及re模块中的常用函数详解

《Python正则表达式语法及re模块中的常用函数详解》这篇文章主要给大家介绍了关于Python正则表达式语法及re模块中常用函数的相关资料,正则表达式是一种强大的字符串处理工具,可以用于匹配、切分、... 目录概念、作用和步骤语法re模块中的常用函数总结 概念、作用和步骤概念: 本身也是一个字符串,其中

Python中的getopt模块用法小结

《Python中的getopt模块用法小结》getopt.getopt()函数是Python中用于解析命令行参数的标准库函数,该函数可以从命令行中提取选项和参数,并对它们进行处理,本文详细介绍了Pyt... 目录getopt模块介绍getopt.getopt函数的介绍getopt模块的常用用法getopt模

Java程序进程起来了但是不打印日志的原因分析

《Java程序进程起来了但是不打印日志的原因分析》:本文主要介绍Java程序进程起来了但是不打印日志的原因分析,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Java程序进程起来了但是不打印日志的原因1、日志配置问题2、日志文件权限问题3、日志文件路径问题4、程序

Java字符串操作技巧之语法、示例与应用场景分析

《Java字符串操作技巧之语法、示例与应用场景分析》在Java算法题和日常开发中,字符串处理是必备的核心技能,本文全面梳理Java中字符串的常用操作语法,结合代码示例、应用场景和避坑指南,可快速掌握字... 目录引言1. 基础操作1.1 创建字符串1.2 获取长度1.3 访问字符2. 字符串处理2.1 子字

python logging模块详解及其日志定时清理方式

《pythonlogging模块详解及其日志定时清理方式》:本文主要介绍pythonlogging模块详解及其日志定时清理方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录python logging模块及日志定时清理1.创建logger对象2.logging.basicCo

前端CSS Grid 布局示例详解

《前端CSSGrid布局示例详解》CSSGrid是一种二维布局系统,可以同时控制行和列,相比Flex(一维布局),更适合用在整体页面布局或复杂模块结构中,:本文主要介绍前端CSSGri... 目录css Grid 布局详解(通俗易懂版)一、概述二、基础概念三、创建 Grid 容器四、定义网格行和列五、设置行

Qt spdlog日志模块的使用详解

《Qtspdlog日志模块的使用详解》在Qt应用程序开发中,良好的日志系统至关重要,本文将介绍如何使用spdlog1.5.0创建满足以下要求的日志系统,感兴趣的朋友一起看看吧... 目录版本摘要例子logmanager.cpp文件main.cpp文件版本spdlog版本:1.5.0采用1.5.0版本主要