在 codeigniter 中分离 Admin 和 Front [英] Separate Admin and Front in codeigniter

查看:26
本文介绍了在 codeigniter 中分离 Admin 和 Front的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 codeigniter 中将网站的管理和前端分开的最佳方法是什么,因为我要使用所有库、模型、助手等,但只有控制器和视图是分开的.

What is the best way to separate admin and front-end for a website in codeigniter where as I was to use all libraries, models, helpers etc. in common, but only controllers and Views will be separate.

我想要一种更合适的方式,以提高性能、简单性以及共享模型和库等.

I want a more proper way, up for performance, simplicity, and sharing models and libraries etc.

推荐答案

我强烈建议阅读 CI 开发人员 Phil Sturgeon 在本文中概述的方法:

I highly suggest reading the methods outlined in this article by CI dev Phil Sturgeon:

http://philsturgeon.co.uk/blog/2009/07/Create-an-Admin-panel-with-CodeIgniter

我的建议:使用模块来组织您的项目.

My advice: Use modules for organizing your project.

https://bitbucket.org/wiredesignz/codeigniter-modular-扩展-hmvc/wiki/主页

为前端和/或后端创建一个基础控制器.像这样:

Create a base controller for the front and/or backend. Something like this:

// core/MY_Controller.php
/**
 * Base Controller
 * 
 */ 
class MY_Controller extends CI_Controller {
                      // or MX_Controller if you use HMVC, linked above
    function __construct()
    {
        parent::__construct();
        // Load shared resources here or in autoload.php
    }
}

/**
 * Back end Controller
 * 
 */ 
class Admin_Controller extends MY_Controller {

    function __construct()
    {
        parent::__construct();
        // Check login, load back end dependencies
    }
}

/**
 * Default Front-end Controller
 * 
 */ 
class Public_Controller extends MY_Controller {

    function __construct()
    {
        parent::__construct();
        // Load any front-end only dependencies
    }
}

后端控制器将扩展Admin_Controller,前端控制器将扩展Public_Controller.前端基本控制器并不是真正必需的,但作为示例,它可能很有用.如果需要,您可以扩展 MY_Controller.

Back end controllers will extend Admin_Controller, and front end controllers will extend Public_Controller. The front end base controller is not really necessary, but there as an example, and can be useful. You can extend MY_Controller instead if you want.

在需要时使用 URI 路由,并为前端和后端创建单独的控制器结尾.如果前端和后端控制器都位于同一个应用程序中,则可以共享所有帮助程序、类、模型等.

Use URI routing where needed, and create separate controllers for your front end and back end. All helpers, classes, models etc. can be shared if both the front and back end controllers live in the same application.

这篇关于在 codeigniter 中分离 Admin 和 Front的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆