- 浏览: 13640466 次
- 性别:
- 来自: 洛杉矶
文章分类
- 全部博客 (1994)
- Php / Pear / Mysql / Node.js (378)
- Javascript /Jquery / Bootstrap / Web (435)
- Phone / IOS / Objective-C / Swift (137)
- Ubuntu / Mac / Github / Aptana / Nginx / Shell / Linux (335)
- Perl / Koha / Ruby / Markdown (8)
- Java / Jsp (12)
- Python 2 / Wxpython (25)
- Codeigniter / CakePHP (32)
- Div / Css / XML / HTML5 (179)
- WP / Joomla! / Magento / Shopify / Drupal / Moodle / Zimbra (275)
- Apache / VPN / Software (31)
- AS3.0/2.0 / Flex / Flash (45)
- Smarty (6)
- SEO (24)
- Google / Facebook / Pinterest / SNS (80)
- Tools (22)
最新评论
-
1455975567:
xuezhongyu01 写道wocan23 写道我想问下那个 ...
Mysql: LBS实现查找附近的人 (两经纬度之间的距离) -
xuezhongyu01:
wocan23 写道我想问下那个111.1是怎么得来的我也看不 ...
Mysql: LBS实现查找附近的人 (两经纬度之间的距离) -
18335864773:
试试 pageoffice 在线打开 PDF 文件吧. pag ...
jquery在线预览PDF文件,打开PDF文件 -
青春依旧:
opacity: 0.5; 个人喜欢这种方式!关于其他css特 ...
css透明度的设置 (兼容所有浏览器) -
July01:
推荐用StratoIO打印控件,浏览器和系统的兼容性都很好,而 ...
搞定网页打印自动分页问题
Create an Admin panel with CodeIgniter
As I see it there are three methods to creating an admin system using the MVC framework CodeIgniter . In this article I will show examples of the structures for each and mention the pro's and con's of using each.
This article will only outline the theory and suggest the structures to you. I do not plan on writing yet another "How to make a user login system and add admins to it" type article.
1.) Two applications
In CodeIgniter you can easily set up multiple applications to run off the same CodeIgniter install, simply by creating a copy of index.php and renaming it to something else.
/ applications/ frontend/ controllers/ home.php blog.php comments.php models/ blog_model.php comment_model.php views/ blogs/ index.php view.php comment/ view.php index.php backend/ config/ controllers/ dashboard.php blog.php comments.php models/ blog_model.php comment_model.php views/ blogs/ index.php form.php comment/ index.php dashboard.php login.php system/ index.php admin/ index.php
Here you can see I have put index.php into an admin/ folder of its own. Both index.php files will point to a single folder within /applications and this can be done by setting:
index.php
$application_folder = "applications/frontend";
admin/index.php
$application_folder = "applications/backend";
This method does work, but is only really any good for big sites that have very different content for their front and back ends. You cannot use the same libraries, helpers, models, etc which will mean its very easy to end up with duplicated code. I'm not a big fan of such frontend/backend separation as for most sites, an admin panel will use the same models and code but this varies entirely on the spec of the site you are building.
2.) Sub-directories
This method follows a more usual CodeIgniter set-up and is the way that most new CodeIgniter users will try things at first.
/ application/ config/ controllers/ admin/ blog.php comments.php blog.php comments.php models/ blog_model.php comments_model.php views/ admin/ blog/ index.php form.php comments/ index.php form.php dashboard.php login.php blog/ index.php view.php comments/ view.php system/ index.php
Here we are keeping the default MVC structure of CodeIgniter and using sub-directories for our controllers to give us the http://example.com/admin/blog URL structure. This method has the advantage of being able to share models, libraries and helpers across both the front and backend. If you really need to separate models for front and back ends, why not just have a models/admin/ folder and put them in there?
The down side is that when your site expands and more controllers are required, it can be a real pain to have your content so loosely linked across the entire application directory. You can see in the example above that we have several folders for blog and comment content, where really we should only have one. This one folder is called a module...
3.) Modules
To keep all the content under one single folder we can adopt the HMVC approach. This stands for Hierarchal MVC which essentially is just modular CodeIgniter. Two systems have been developed for this: HMVC and Matchbox . I personally prefer use the latter but have never tried HMVC so i'll leave that one up to you.
A strange thing that many CodeIgniter users seem to do is create a blog module, comment module and admin module. This strikes me as a very strange separation of content that goes against the point of using modules in the first place! I have a single admin.php controller in the main controllers folder to act as the default admin page which will handle login, logout and the main dashboard. Then I add another admin.php controller in each module and use URI Routing to get my URL structure as http://example.com/admin/.
/ application/ config/ controllers/ admin.php modules/ blog/ controllers/ admin.php blog.php models/ blog_model.php views/ admin/ index.php form.php comments/ controllers/ admin.php comments.php models/ comment_model.php views/ admin/ index.php form.php views/ admin/ dashboard.php login.php system/ index.php
Right now to get at the blog admin you would have to go to http://example.com/blog/admin which may well be fine with you. If not, you can add the following routes to your application/config/routes.php to swap the segments around and emulate a /admin/ folder.
$route['admin/([a-zA-Z_-]+)/(:any)'] = '$1/admin/$2'; $route['admin/login'] = 'admin/login'; $route['admin/logout'] = 'admin/logout'; $route['admin/([a-zA-Z_-]+)'] = '$1/admin/index'; $route['admin'] = 'admin';
This way you have your admin controllers kept with the frontend controllers, you are sharing models, libraries and helpers and you still have some nice URL's.
Summary
If your front and back end applications share nothing in common and never will do, use method #1. If you have a small site with one a few controllers and do not want the small overhead HMVC adds, use method #2. If you are working on a massive site that is modular and shares code between front and back ends, use method #3.
Got any more methods to handle admin structures? Let me know in the comments.
发表评论
-
CakePHP你必须知道的21条技巧
2012-10-19 06:25 1849原文链接:http://www.avatarfinancial ... -
cakephp 1.3 Views
2012-10-09 06:12 1409Section 1 Views 视图 一个vie ... -
cakephp 1.3 Models
2012-10-09 06:07 2474Section 1 What is a model? ... -
cakephp 1.3 Controller
2012-10-09 05:49 3299Controller 一个controller用于管理 ... -
cakephp 1.3 配置CakePHP
2012-10-09 05:31 4602Section 1 数据库配置 app/config/ ... -
CakePHP 2.x十分钟博客教程
2012-10-07 01:27 243681. CakePHP2十分钟博客教 ... -
Codeigniter Grid 使用方法 (flexigrid)
2010-05-23 02:05 2766来源:http://codeigniter.com/forum ... -
CI集成 ckeditor 配置
2010-05-23 01:34 3723配置 ckeditor 1.上传 下载 ckedito ... -
codeigniter 辅助函数 - 敏感词过滤
2010-05-05 06:18 4543我们都知道有些敏感的词汇是不适合出现在互联网上的,特别是在有用 ... -
实现简单 codeigniter 缓存 (cache)
2010-04-30 23:47 5236代码 class Test extends Contr ... -
CKEditor Helper for CodeIgniter
2010-04-19 00:37 3943Using CKEditor as a plugin in y ... -
codeigniter 生成 excel
2010-04-19 00:33 3288Excel Plugin Th ... -
CakePHP 中文手册
2010-04-14 21:04 2310基本概念 Section1 简介 ... -
利用 Cache_Lite代替codeigniter中的cache功能
2010-01-29 06:15 5473codeigniter的功能纵然强大,也有不足之处。其cach ... -
CodeIgniter 操作PDF ( Generating PDF files using CodeIgniter )
2010-01-03 04:03 3572PDF files rock! Some of the p ... -
CodeIgniter 合作 Authorize.net
2009-12-30 00:25 1559function payment(){ // 略... ... -
CodeIgniter 合作paypal
2009-12-30 00:15 2317<?php class Paypal extend ... -
CodeIgniter 操作 CSV
2009-12-29 07:17 4582A Comma separated values (CSV) ... -
codeigniter 操作 Rss
2009-12-29 07:12 1927I wrote a codeigniter library t ... -
codeigniter操作xml
2009-12-29 06:57 3957This Simplexml class provides a ...
相关推荐
CodeIgniter-admin-panel, 使用 Twitter Bootstrap的管理员面板的CodeIgniter模板 CodeIgniter-Sample-Project使用 Twitter 2.1.2和 Bootstrap的示例管理员面板。我想让大家知道,想法是接受建议,并且随着社区的...
基于 vue-element-admin 和 PHP CodeIgniter RES-vue-php-admin
CodeIgniter-Admin-Panel 该项目是使用CodeIgniter 3开发的。 被用作该项目的主题。
Codeigniter-php-Bootstrap-Admin-Panel和用户管理 具有用户管理功能的Codeigniter Bootstrap管理面板 Bootstrap是最流行HTML,CSS和JS框架,用于在Web上开发响应式,移动优先项目。 它是为自定义CodeIgniter项目...
SatSun CRMS beta0.1(for CodeIgniter) SatSun CRMS beta0.1(with CodeIgniter) SatSun CRMS beta0.1(for CodeIgniter) SatSun CRMS beta0.1(with CodeIgniter)
Loosely based on the Model-View-Controller pattern, CodeIgniter is an open source framework for application development. It allows you to develop projects by providing a rich set of libraries for ...
CodeIgniter最新版本,开源、免费、轻量级的web编程,基于MVC的编程架构能大大提高php编码生产力。
PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter...
codeigniter的是使用例程,使用了mvc的典型架构,例子比较简单,不过涉及了ci的常见问题。表单,ajax,view等等
Source Server : mysql_localhot Source Server Type : MySQL Source Server Version : 50624 Source Host : localhost Source Database : codeigniter Target Server Type : MySQL Target Server Version : 50624 ...
CodeIgniter框架
codeigniter-3.2.1-with-admin-LTE-Template-Intigration带有php codeigniter 3.2.1的最新版Admin LTE Templete 从存储库下载代码。 解压缩该zip文件。 打开浏览器; 转到localhost / phpmyadmin。 在该数据库中导入...
codeigniter 代码实例分享,基于jquery1.4,codeigniter,eclipse 开发
element-admin 和 PHP CodeIgniter RESTful 实现,采用前后端分离架构的权限管理系统,PHP快速开发平台,目标是搭建一套简洁易用的快速解决方案,可以帮助用户有效降低项目开发难度和成本。以vue-element-admin@...
PacktPub.Programming.with.CodeIgniter.MVC.Sep.2013
Codeigniter Grid 使用方法 (flexigrid) 博客分类: Codeigniter / CakePHP ASPRailsRubyPHPGoogle 来源:http://codeigniter.com/forums/viewthread/75326/P0/ Updated: 6 September 2008 Although I love CI, ...
敏捷php开发框架CodeIgniter 1.7.1中文手册
CodeIgniter_2.1.4.zip
codeigniter分页