CI framework integration widget (page pattern) method, ciwidget
This article describes how to integrate widgets (page pattern) in the CI framework. We will share this with you for your reference. The details are as follows:
In the WEB development process, we inevitably need to output view files. Generally, view files have common elements such as headers, left sidebar, and bottom.
How can we make the whole project development introduce agile thinking when it involves View sets to improve efficiency? You have to mention the widget. You can also use the HMVC model.
Here we will only introduce how widgets are integrated into the CI framework:
1. Add the call 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 a widget file:
<? Php/* ------------ widget. php components include their own controllers, views, and models (common models can be shared) * used to implement the public part 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 (); $ thi S-> load-> view ('com/left. php', $ data) ;}}?>
3. Call in the View File (the widget method in the parent class control should be called in the corresponding controller first ):
<!--left sider --><div><?php Widget::left();?></div>...<!--/left sider -->