During web development,We can't avoid outputting the view file,In general, the view file usually requires the common elements of the header, left side bar, and bottom.

How to make the entire project development introduce agile thinking when it comes to view application,How about efficiency?I have to mention the widget. It is true that you can also use the hmvc model.

Here is only how to integrate the widget into the ci framework:

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

* If $name exists, call the widget class and widget method
*@param string $name
* /
protected function widget ($name="")
    if (isset ($name)&&$name!="")
      require_once base_widget. $name. ". php";

2. Define the widget class file:

/* ------------
The widget.php component contains its own controller,View, model (can share common model)
* Used to implement the common parts of each page
@author crystal 20120106
-------------- * /
class widget extends my_controller
  private function __construct ()
    parent ::my_controller ();
  /*** Get the current class name * /
  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);

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

<!-Left sider->
<?php widget ::left ();?>
<!-/Left sider->
  • Previous A little personal understanding of the JavaScript prototype chain
  • Next C # send message to windowless process