CI框架整合widget(页面格局)的方法_php实例
本文实例讲述了CI框架整合widget(页面格局)的方法。分享给大家供大家参考,具体如下:
在WEB开发过程中,我们免不了要输出视图文件,而通常视图文件又一般都少不了头部、左侧栏以及底部这些公共元素。
如何让整个项目开发在涉及视图套用时引入敏捷的思维,提高效率呢?就不得不提一下widget。承然你也大可以使用HMVC模型。
这里仅介绍下widget如何结合入CI框架中:
1、在类文件MY_Controller.php中添加调用方法:
/* * 如果$name存在则调用widget类及widget方法 *@param string $name */ protected function widget ($name = '') { if (isset($name) && $name != '') { require_once BASE_WIDGET.$name.'.php'; } }
2、定义widget类文件:
<?php /*------------ widget.php 组件包含自己的控制器,视图,模型(可以共用普通model) *用来实现各页面都有的公共部分 @author crystal 20120106 --------------*/ class Widget extends MY_Controller { private function __construct() { parent::MY_Controller(); } /*** 获取当前类名*/ 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、在视图文件中调用(在相应的控制器中应该先调用父类控制中的widget方法):
<!--left sider --> <div> <?php Widget::left();?> </div> ... <!--/left sider -->
更多关于CodeIgniter相关内容感兴趣的读者可查看本站专题:《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《php优秀开发框架总结》、《ThinkPHP入门教程》、《ThinkPHP常用方法总结》、《Zend FrameWork框架入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家基于CodeIgniter框架的PHP程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

With the development of network technology, PHP has become one of the important tools for Web development. One of the popular PHP frameworks - CodeIgniter (hereinafter referred to as CI) has also received more and more attention and use. Today, we will take a look at how to use the CI framework. 1. Install the CI framework First, we need to download the CI framework and install it. Download the latest version of the CI framework compressed package from CI's official website (https://codeigniter.com/). After the download is complete, unzip

With the development of the Internet, big data analysis and real-time information processing have become an important need for enterprises. In order to meet such needs, traditional relational databases no longer meet the needs of business and technology development. Instead, using NoSQL databases has become an important option. In this article, we will discuss the use of SpringBoot integrated with NoSQL databases to enable the development and deployment of modern applications. What is a NoSQL database? NoSQL is notonlySQL

PHP is a popular programming language that is widely used in web development. The CI (CodeIgniter) framework is one of the most popular frameworks in PHP. It provides a complete set of ready-made tools and function libraries, as well as some popular design patterns, allowing developers to develop Web applications more efficiently. This article will introduce the basic steps and methods of developing PHP applications using the CI framework. Understand the basic concepts and structures of the CI framework. Before using the CI framework, we need to understand some basic concepts and structures. Down

UniApp realizes the perfect integration of the Vue.js framework Introduction: UniApp is a cross-platform development tool based on the Vue.js framework. It can compile a Vue.js project into applications for multiple different platforms, such as iOS, Android, small Programs etc. The advantage of UniApp is that it allows developers to write only one set of code and adapt to multiple platforms at the same time, speeding up development efficiency and reducing development costs. The following will introduce how to use UniApp to achieve perfect integration of the Vue.js framework

PHP is a widely used server-side scripting language, and CodeIgniter4 (CI4) is a popular PHP framework that provides a fast and excellent way to build web applications. In this article, we will get you started using the CI4 framework to develop outstanding web applications by walking you through how to use it. 1. Download and install CI4 First, you need to download it from the official website (https://codeigniter.com/downloa

Changes in Vue3 compared to Vue2: More powerful network request library integration As Vue.js continues to develop and update, Vue3, as the next version of Vue.js, brings some exciting changes and improvements. One of the most significant changes is more powerful network request library integration. In Vue2, we usually use third-party libraries such as axios to make network requests. In Vue3, the Vue development team has provided a built-in network request library, which provides us with a more intuitive and flexible method.

Practical tips for integrating PHPcms with other systems With the continuous development of Internet technology, the field of website development has become more diverse and complex. In actual projects, we often face situations where different systems need to be integrated, which requires us to have certain skills and experience to solve these problems. This article will introduce some practical tips and specific code examples for the integration of the PHPcms system with other systems to help developers better cope with challenges. 1. Basic Principles of Integration When performing system integration, it is first necessary to

With the development of the Internet and its continuous integration into people's lives, the development of network applications has become more and more important. As a well-known programming language, PHP has become one of the preferred languages for developing Internet applications. Developers can use numerous PHP frameworks to simplify the development process, one of the most popular is the CodeIgniter (CI) framework. CI is a powerful PHP web application framework. It has the characteristics of lightweight, easy to use, optimized performance, etc., allowing developers to quickly build
