CI Framework Integration Widget (page pattern) method _php Example

Source: Internet
Author: User
Tags codeigniter zend framework

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.