首页 技术 正文
技术 2022年11月19日
0 收藏 459 点赞 2,775 浏览 4528 个字

 (参考网上相关文章,进行测试点评,下述方法测试成功)

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’);
      $goods=$test_mod->getAll(“select * from ecm_goods where goods_id =1”);
      return $goods;     }   }   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=good}–>                       <li>{$good[goods_name]}</li>                      <!–{/foreach}–>               </ul>              </div>          </div>       </div>    挂件开发说明     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’));    }  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,564
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,412
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,185
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905