Home >Backend Development >PHP Tutorial >How to integrate widget (page layout) with CI framework, ciwidget_PHP tutorial

How to integrate widget (page layout) with CI framework, ciwidget_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:52:12793browse

How the CI framework integrates widgets (page layout), ciwidget

This article describes how the CI framework integrates widgets (page layout). Share it with everyone for your reference, the details are as follows:

In the process of WEB development, we inevitably have to output view files, and usually view files generally contain common elements such as the header, left column, and bottom.

How to introduce agile thinking into the entire project development when it comes to view application and improve efficiency? I have to mention widgets. Of course you can also use the HMVC model.

Here we only introduce how widgets are integrated into the CI framework:

1. Add the calling method in the class file MY_Controller.php:

/*
* 如果$name存在则调用widget类及widget方法
*@param string $name
*/
protected function widget ($name = '')
{
    if (isset($name) && $name != '')
    {
      require_once BASE_WIDGET.$name.'.php';
    }
}

2. Define widget class file:

<&#63;php
/*------------
widget.php 组件包含自己的控制器,视图,模型(可以共用普通model)
*用来实现各页面都有的公共部分
@author crystal 20120106
--------------*/
class Widget extends MY_Controller
{
  private function __construct()
  {
    parent::MY_Controller();
  }
  /*** 获取当前类名*/
  private static function _getClass()
  {
    return __CLASS__;
  }
  public static function left()
  {
    $class = self::_getClass();
    $data['userinfo'] = MY_Controller::_getUserCookieInfo();
    $this->load->view('com/left.php',$data);
  }
}
&#63;>

3. Call in the view file (the widget method in the parent class control should be called first in the corresponding controller):

<!--left sider -->
<div>
<&#63;php Widget::left();&#63;>
</div>
...
<!--/left sider -->

Readers who are interested in more CodeIgniter related content can check out the special topics of this site: "codeigniter introductory tutorial", "CI (CodeIgniter) framework advanced tutorial", "php excellent development framework summary", "ThinkPHP introductory tutorial", "Summary of Common Methods in ThinkPHP", "Introduction Tutorial on Zend FrameWork Framework", "Introduction Tutorial on PHP Object-Oriented Programming", "Introduction Tutorial on PHP MySQL Database Operation" and "Summary of Common PHP Database Operation Skills"

I hope this article will be helpful to everyone’s PHP program design based on the CodeIgniter framework.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1127870.htmlTechArticleHow to integrate widget (page layout) with CI framework, ciwidget This article describes the CI framework integration widget (page layout) with an example method. Share it with everyone for your reference, the details are as follows: Developing in WEB...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn