ecmall widgets 挂件开发详解

简介: Ecmall挂件开发 实质上是后台开发很多页面,分别去调用程序展示这些页面,达到首页内容更换很快的目的,这样做减少后续开发,开发人员只需开发挂件就可以了,至于位置可随意定.(还需调整html,但是起码后台取数据不用做了) 流程介绍: 1:ecmall模板页面调用widget页面(整个过程比较复杂)   参数:page:指明页面是index页面      Area:指明显示的区域。
Ecmall挂件开发
实质上是后台开发很多页面,分别去调用程序展示这些页面,达到首页内容更换很快的目的,这样做减少后续开发,开发人员只需开发挂件就可以了,至于位置可随意定.(还需调整html,但是起码后台取数据不用做了)
流程介绍:
1:ecmall模板页面调用widget页面(整个过程比较复杂)
  <!--{widgets page=index area=cycle_image}-->
参数:page:指明页面是index页面
     Area:指明显示的区域。(相当于告诉程序生成的页面是放在那里的)
2:经过ecmall模板引擎重新生成一个临时php文件,上面那句代码被解析成这样的php代码。
<!--{widgets page=index area=cycle_image}-->
                     ||
<?php $this->display_widgets(array('page'=>'index','area'=>'cycle_image')); ?>
 
3:查看下display_widgets()方法的源码
/**
* 视图回调函数[显示小挂件]
*
* @author    Garbin
* @param     array $options
* @return    void
*/
function display_widgets($options) {
$area = isset ( $options ['area'] ) ? $options ['area'] : '';
$page = isset ( $options ['page'] ) ? $options ['page'] : '';
if (! $area || ! $page) {
return;
}
include_once (ROOT_PATH . '/includes/widget.base.php');
 
/* 获取该页面的挂件配置信息 */
$widgets = get_widget_config ( $this->_get_template_name (), $page );
 
/* 如果没有该区域 */
if (! isset ( $widgets ['config'] [$area] )) {
return;
}
 
/*将该区域内的挂件依次显示出来 */
foreach ( $widgets ['config'] [$area] as $widget_id ) {
$widget_info = $widgets ['widgets'] [$widget_id];
$wn = $widget_info ['name'];
$options = $widget_info ['options'];
 
$widget = & widget ( $widget_id, $wn, $options );
$widget->display ();
}
}
 
/**
* 获取当前使用的模板名称
*
* @author    Garbin
* @return    string
*/
function _get_template_name() {
return 'default';
}
 
/**
*    获取指定风格,指定页面的挂件的配置信息
*
*    @author    Garbin
*    @param     string $template_name
*    @param     string $page
*    @return    array
*/
function get_widget_config($template_name, $page)//default index
{
    static $widgets = null;
    $key = $template_name . '_' . $page;
    if (!isset($widgets[$key]))
    {
        $tmp = array('widgets' => array(), 'config' => array());
        $config_file = ROOT_PATH . '/data/page_config/' . $template_name . '.' . $page . '.config.php';
        if (is_file($config_file))
        {
            /* 有配置文件,则从配置文件中取 */
            $tmp = include_once($config_file);
        }
 
        $widgets[$key] = $tmp;
    }
 
    return $widgets[$key];
}
 
 
/**
*    获取挂件实例
*
*    @author    Garbin
*    @param     string $id
*    @param     string $name
*    @param     array  $options
*    @return    Object Widget
*/
function &widget($id, $name, $options = array())
{
    static $widgets = null;
    if (!isset($widgets[$id]))
    {
        $widget_class_path = ROOT_PATH . '/external/widgets/' . $name . '/main.widget.php';
        $widget_class_name = ucfirst($name) . 'Widget';
        include_once($widget_class_path);
        $widgets[$id] = new $widget_class_name($id, $options);
    }
 
    return $widgets[$id];
}
 
    /**
     *    显示
     *
     *    @author    Garbin
     *    @param    none
     *    @return    void
     */
    function display()
    {
        echo $this->get_contents();
}
 
    /**
     *    将取得的数据按模板的样式输出
     *
     *    @author    Garbin
     *    @return    string
     */
    function get_contents()
    {
        /* 获取挂件数据 */
        $this->assign('widget_data', $this->_get_data());
 
        /*可能有问题*/
        $this->assign('options', $this->options);
        $this->assign('widget_root', $this->widget_root);
 
        return $this->_wrap_contents($this->fetch('widget'));
    }
 
 
实例开发:
1:在页面上添加要展示的页面模块
<div class="left" area="bottom_foot" widget_type="area">
    <!--{widgets page=index area=bottom_foot}-->
</div>
2:修改工程目录下/data/page_config/default.index.config.php添加该模块的相关信息
   'widgets' => 
  array (
     '_widget_1000' => 
                 array (
                 'name' => 'test',
                 'options' => 
                             array (
                             'ad_image_url' => 'data/files/mall/template/200908070207084061.gif',
                             'ad_link_url' => '',
                              ),
                 ),
  ),
  'config' => 
    array(
      'bottom_foot' => 
      array (
            0 => '_widget_1000',
            ),
),
 
3:在工程目录external/widgets建name(跟上面定义的name要一致)目录,然后再建文件main.widget.php  
  class TestWidget extends BaseWidget{
    var $_name = 'test';
    function _get_data(){
      $test_mod=&m('test');
      $users=$test_mod->getAll("select * from ecm_member");
          return $users;
    }
  }  
4:在includes/model下建模型文件(同数据库交互)
  class TestModel extends BaseModel{
      
     
   }
5:在同级目录创建widget.html文件(该模板为展示内容)
<div class="module_common">
    <h2><b class="news" title="NEWS公告栏"></b></h2>
    <div class="wrap">
        <div class="wrap_child">
            <ul class="news_list">
                <!--{foreach from=$widget_data item=user}-->
                <li>{$user[user_name]}</li>
                <!--{/foreach}-->
            </ul>
        </div>
    </div>
</div>
目录
相关文章
|
29天前
|
计算机视觉 C++
基于Qt的简易图片浏览器设计与实现
基于Qt的简易图片浏览器设计与实现
27 1
|
16天前
|
图形学 Python 容器
【PyQt5桌面应用开发】3.Qt Designer快速入门(控件详解)
【PyQt5桌面应用开发】3.Qt Designer快速入门(控件详解)
35 0
|
2月前
qt 开发 “控件之家“
qt 开发 “控件之家“
|
C++
Qt功能优化:Qt 3D画廊
Qt功能优化:Qt 3D画廊
212 1
Qt功能优化:Qt 3D画廊
Qt实用技巧:Qt从QtCreator更换为VS开发Qt所需要注意的坑
Qt实用技巧:Qt从QtCreator更换为VS开发Qt所需要注意的坑
Qt实用技巧:Qt从QtCreator更换为VS开发Qt所需要注意的坑
Qt QWidget 软件开发模版
Qt QWidget 软件开发模版
105 0
Qt QWidget 软件开发模版
|
Python
PyQt5 技术篇 - Qt Designer怎么用styleSheet设置按钮的背景
PyQt5 技术篇 - Qt Designer怎么用styleSheet设置按钮的背景
558 0
PyQt5 技术篇 - Qt Designer怎么用styleSheet设置按钮的背景
|
数据安全/隐私保护
8、QT基础——常用控件
8、QT基础——常用控件
283 0
8、QT基础——常用控件
|
前端开发 存储 数据库