在 codeigniter 中分离 Admin 和 Front

发布于 2024-12-06 07:19:08 字数 113 浏览 1 评论 0原文

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

魄砕の薆 2024-12-13 07:19:08

我强烈建议阅读 CI 开发者 Phil Sturgeon 在这篇文章中概述的方法:

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

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

https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc /wiki/Home

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

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

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

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

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.

凉墨 2024-12-13 07:19:08

我使用一个非常简单的方法:文件夹。查看 CI 用户指南部分,将控制器组织到子文件夹中。

我构建了面向公众的网站,就像使用 CodeIgniter 构建的任何其他网站一样。然后我有两个额外的文件夹,controllers/adminviews/admin

管理控制器通过http://[主机名]/admin/controller进行访问,其行为与任何其他控制器一样,只是它们具有特定的身份验证检查。同样,只需使用包含的文件夹名称来调用视图:$this->load->view('admin/theview');

我还没有找到比这更复杂的理由。

I use a very simple approach: file folders. Check out the CI User Guide section, Organizing Your Controllers into Sub-folders.

I have my public-facing website built as any other would be built with CodeIgniter. Then I have two additional folders, controllers/admin and views/admin.

The admin controllers are accessed via http://[hostname]/admin/controller, and behave just as any other controller except they have specific authentication checks. Likewise, the views are simply called with the folder name included: $this->load->view('admin/theview');.

I haven't found a reason to do anything more complicated than that.

北陌 2024-12-13 07:19:08

大家都可以在这里找到完整的解决方案, https://github.com/bhuban/modular

模块分离使用 HMVC 进行管理和前端,使用模板库进行模板分离

我正在使用两个第三方库,您可以在 zip 文件中找到它。

  1. 由wiredesignz开发的用于模块化的HMVC
  2. 由Phil Sturgeon开发的用于模板化的模板引擎

只需将其解压到您的网络服务器根目录并运行

localhost/modular for front-end

localhost/modular/admin for back-end

application/back-modules,它用于后端模块

application/ 是针对前端模块

front-modules,同样
templates/admin 用于后端模板
templates/front 用于前端模板

themes/admin 用于后端主题
用于前端主题的 themes/front

原始代码中没有任何内容,只是使用 config.php 和 index.php 配置

You all can find complete solution over here, https://github.com/bhuban/modular

Module separation for admin and front-end using HMVC and template separation using template libraries

I am using two third party libraries, you can find it in zip file.

  1. HMVC for modular developed by wiredesignz
  2. Template engine for templating by Phil Sturgeon

Just unzip it into your webserver root directory and run

localhost/modular for front-end

and

localhost/modular/admin for back-end

application/back-modules, it is for the back-end modules

application/front-modules, it is for the front-end modules

similarly
templates/admin for the back-end templates
templates/front for the front-end templates

themes/admin for the back-end themes
themes/front for the front-end themes

Nothing hacked in original code just configured using config.php and index.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文