在codeigniter中单独管理和前端 [英] Separate Admin and Front in codeigniter

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

问题描述

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

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-extensions-hmvc/wiki/Home

为前端和/或后端创建基本控制器。像这样:

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



b
$ b

后端控制器将扩展Admin_Controller ,前端控制器将扩展Public_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.

使用

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中单独管理和前端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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