1

actually i am looking to handle my website/admin panel withing same application. so i want to know that is that possible?

i means structure something like this
http://www.mysite.com
and for admin
http://www.mysite.com/admin

so this all i need to handle withing one application of codeignitor. i don't want two codeignitor installation for this purpose.

naeplus
  • 121
  • 3
  • 14

2 Answers2

3

Sure, you can, see the section at CI docs which says:

Running Multiple Applications with one CodeIgniter Installation

You can also create separate folders for your controllers, models and views like:

+controllers
    +front (main site controllers will go here)
    +admin (admin controllers will go here)

+models
    +front (main site models will go here)
    +admin (admin models will go here)

+views
    +front (main site views will go here)
    +admin (admin views will go here)

See the section:

Organizing Your Controllers into Sub-folders

Sarfraz
  • 377,238
  • 77
  • 533
  • 578
  • thanks sarfraz, i was using +front +admin technique which is easy to handle. but here i am facing a problem with (organizing your controller to subfolder.) i defined sub-folder route in to routes.php but it seems not working – naeplus Feb 01 '12 at 16:51
  • @Naeem: Welcome, for your routing issue, you should post another question with how you have done it and what issue you are having :) – Sarfraz Feb 01 '12 at 16:55
  • what may be the reason? $route['admin/players'] = "admin/players/players"; here i defined the admin/players folder route. but its still showing error404. – naeplus Feb 01 '12 at 16:55
  • i am posting another question. please come with me there. – naeplus Feb 01 '12 at 16:57
  • http://stackoverflow.com/questions/6529026/codeigniter-default-controller-in-a-sub-directory-not-working please come there and post your anwser. – naeplus Feb 01 '12 at 17:38
  • @Naeem: I saw your second question, looks ok to me (it's been quite some time i worked on ci too). The link you showed might be helpful to see eg: http://stackoverflow.com/questions/6529026/codeigniter-default-controller-in-a-sub-directory-not-working – Sarfraz Feb 01 '12 at 17:44
  • i looked at that link first.but its problem with subfolder within subfolder routes. so its not working and no one is posting anwser. – naeplus Feb 01 '12 at 17:51
  • Try adding this `$route['folder'] = "admin";` before `$route['admin/players'] = "admin/players/players"; `. You might need to change `$route['admin/players'] = "admin/players/players"; ` to `$route['admin/players'] = "players/players"; ` it it still does not work. – Sarfraz Feb 01 '12 at 17:56
  • i did it. but its still not working. in that question folder is some folder name. and for me it is 'admin'. i try changing all this. but its still showing error. – naeplus Feb 01 '12 at 18:10
0

First 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 MY_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
        // Create and setup admin user session and other all dynamic admin url for image,js,css,etc..
    }
}

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

    function __construct()
    {
        parent::__construct();
        // Load any front-end only dependencies
        // Get user data of session and generate other all dynamic front url for image,js,css,etc..
    }
}

Back end controllers will extend Admin_Controller, and front end controllers will extend Front_Controller.Now You can create any admin side controller & models and extends to Admin_Controller and front side extends to Front_Controller.

E.g (Any Admin Controller) :

    class Admin extends Admin_Controller{
      function __construct(){
         parent::__construct();
      }   
    } 

E.g (Any Front Controller) :

    class Home extends Front_Controller{
      function __construct(){
         parent::__construct();
      }   
    } 

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