CodeIgniter CI框架前后台搭建------主控制器拆分为前后台控制器
2013-12-25 22:33
183 查看
CodeIgniter CI框架前后台搭建------主控制器拆分为前后台控制器 终于找到的最好的方法了
在告诉你最好的方法的之前,先说一句话,这个是CI的特点就是这个,不要盲目视图改变。如果想在mvc中分开前后台,最好的方法是方便在mvc三个目录下建好两文件 admin和home。访问是加上文件夹比如 $this->smarty->display('admin/index.html')。 你试试吧。
方法一 (最理想方法看方法三)
http://www.phpwell.com/?p=535
方法二(不是很理想)
管理你的应用程序 默认情况下,你会将应用程序放入application/中,并且可能用 CodeIgniter 只管理这一个应用程序。当然,多个应用程序共享一个 CodeIgniter, 甚至对 application 文件夹进行重命名或更换路径也是可行的。 对应用程序文件夹重命名 如果你要对 application 进行重命名, 你需要打开 index.php 文件,对变量 $application_folder 进行更改: $application_folder = "application"; 更改你的应用程序的文件夹路径 你可以将 application文件夹从system 文件夹中挪放到服务器的其他的位置。但是你还要更改 index.php 文件里将$application_folder变量设置为服务器的全路径。 $application_folder = "/Path/to/your/application"; 在一个 CodeIgniter 下运行多个应用程序 如果你想要多个应用程序共享同一个 CodeIgniter, 你要将 application 下所有的文件夹放在不同的应用程序的文件夹内。 例如,你要建立两个应用程序 "foo" 和 "bar",你的应用程序文件夹的结构可能会像下面的这样: applications/foo/ applications/foo/config/ applications/foo/controllers/ applications/foo/errors/ applications/foo/libraries/ applications/foo/models/ applications/foo/views/ applications/bar/ applications/bar/config/ applications/bar/controllers/ applications/bar/errors/ applications/bar/libraries/ applications/bar/models/ applications/bar/views/ 要选择使用某个应用程序,你需要打开主 index.php 文件,并且设置 $application_folder 变量为目标路径。例如,通过如下设置,就可以选择使用 "foo" 应用程序: $application_folder = "applications/foo"; 注意: 每一个应用程序都会需要它自己的index.php文件来调用他的目标程序。你可以随意对 index.php 文件进行命名。 到这并不是最好的 **********保证数据库配置的重用性************************* 方法三
<?php class Public_Controller extends MY_Controller { function __construct() { parent::__construct(); } } ?> Admin_Controller.php: <?php class Admin_Controller extends MY_Controller { function __construct() { parent::__construct(); } } ?> 这时候要注意在MY_Controller.php里把Public_Controller.php、Admin_Controller.php include进来,如果没有就会出现 Fatal error: Class ‘Public_Controller’ not found in xxx…的错误讯息。 <?php class MY_Controller extends Controller { function __construct() { parent::__construct(); } } // 把MY_Controller.php、Public_Controller.php、Admin_Controller.php都放在applicaton/libraries目录下。 include('Public_Controller.php'); include('Admin_Controller.php'); ?> 另一个方法,是把这些controller class都写在MY_Controller.php <?php class MY_Controller extends Controller { function __construct() { parent::__construct(); } } class Public_Controller extends MY_Controller { function __construct() { parent::__construct(); } } class Admin_Controller extends MY_Controller { function __construct() { parent::__construct(); } } ?>
相关文章推荐
- 从此不求人:自主研发一套PHP前端开发框架(31)搭建后台框架
- SSM框架搭建简单的前后台分离项目(后台篇)
- ThinkPHP--后台首页品字形框架搭建
- golang实战使用gin+xorm搭建go语言web框架restgo详解5.4 控制器参数绑定
- 后台首页品字形(frameset)框架搭建
- 基于EasyUI的通用后台管理系统框架搭建
- 分页插件开发(3)--后台框架搭建
- 【干货】利用MVC5+EF6搭建博客系统(四)(上)前后台页面布局页面实现,介绍使用的UI框架以及JS组件
- golang实战使用gin+xorm搭建go语言web框架restgo详解5.5 控制器模型绑定
- jQuery后台框架搭建
- 整合springboot(app后台框架搭建四)
- 架构实战项目心得(七):使用SpringBoot+Dubbo+Mybatisplus+Oracle搭建后台项目框架(一)
- golang实战使用gin+xorm搭建go语言web框架restgo详解5.6 控制器参数校验
- spring4+springmvc+mybatis基本框架(app后台框架搭建一)
- react前端+node后台+mongoose+express框架搭建
- 使用dwz框架搭建网站后台
- golang实战使用gin+xorm搭建go语言web框架restgo详解5.7 控制器数据响应
- golang实战使用gin+xorm搭建go语言web框架restgo详解5.9 控制器controller编程示例
- ASP.NET MVC搭建项目后台UI框架—1、后台主框架
- java web后台开发SSM框架(Spring+SpringMVC+MyBaitis)搭建与优化