This article gives an example of how the CI Framework consolidates Widgets (page patterns). Share to everyone for your reference, specific as follows:
In the Web development process, we inevitably have to output the view file, and usually the view file is not generally the head, the left side of the bar and the bottom of these common elements.
How do I get the whole project development to introduce agile thinking when it comes to the application of views, and improve efficiency? You have to mention the widget. You can also use the HMVC model.
Here's how widgets are combined into the CI framework:
1, add the calling method in the class file my_controller.php:
*
* If $name exists then invoke Widget class and Widget method
* @param string $name
/protected function widget ($name = ')
{
if (isset ($name) && $name!= ')
{
require_once base_widget. $name. " php ';
}
}
2, the definition of widget class files:
<?php
/*------------
widget.php components contain their own controllers, views, models (can be common model)
* Used to achieve 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 appropriate controller):
<!--left Sider-->
<div>
<?php widget::left ();? >
</div>
...
<!--/left Sider-->
More interested in CodeIgniter related content readers can view the site topics: "CodeIgniter Introductory Course", "CI (CodeIgniter) Framework Advanced Course", "PHP Excellent Development Framework Summary", "thinkphp Introductory Course", " Thinkphp Common Methods Summary, "Zend Framework Introduction Course", "PHP object-oriented Programming Introduction Course", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design based on CodeIgniter framework.