CI framework integration widget (page pattern) method, ciwidget

Source: Internet
Author: User

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 -->

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.