CI framework integration widget (page pattern) method

Source: Internet
Author: User
This article mainly introduces the CI framework integration widget (page pattern) method, analyzes the role of the widget page pattern and the specific implementation method of CI framework integration widget, for more information about how to integrate widgets in the CI framework (page pattern), see the example in this article. 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 ):

 

<?php Widget::left();?>

...

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.