Welcome Guest, Not a member yet? Register   Sign In
Admin controller
#1

[eluser]Unknown[/eluser]
Hi all!

How can I put my admin controllers into ../controllers/admin/controlle_name.php and access them via mysite.com/admin/controller_name/method ???

Does I need to write my own route file or other way???

Thanks!
#2

[eluser]healer[/eluser]
hi,

look in user guide http://ellislab.com/codeigniter/user-gui...subfolders section.

You can put your controller ../controllers/admin/controlle_name.php and you must add new route to your routes.php file like this one
$route['admin'] = 'admin/controller_name';
this is your default controller for admin section. You dont need to add routes for each controller in admin folder. just add for default one.
#3

[eluser]Unknown[/eluser]
Thanks!
The problem was solved! I need to use folder "../modules/admin/controllers/controller_name.php", then I use Modules extension.
#4

[eluser]mamen[/eluser]
Waw Thank's that's Very helpfull

Thank's healer
#5

[eluser]OwanH[/eluser]
Hi Cyrill,

Also note what the user guide says @ http://ellislab.com/codeigniter/user-gui...subfolders. You can create sub-folders within the application/controllers directory and place your controller classes within them.

So... you can create an admin sub-folder in application/controllers and place your admin controllers in there.
#6

[eluser]ntheorist[/eluser]
Hey i'm working on a similar problem. I understand building a subfolder in the controllers folder well enough, but is there a way to simulaneously have each controller in the 'admin' subfolder, extend an admin_controller file, which is itself an extend of controller, so you could add in whatever admin/security functions necessary.. ie
Code:
class Admin_Controller extends Controller
{    
    function Admin_Controller()
    {
        parent::Controller();
        
        $this->auth->authenticate(2);
        
        $this->nsite->depth_nav('Admin', 'home/');
        
        //$this->output->enable_profiler(TRUE);
    }
}
I've had this working so far for me, but the only solution i have is adding a require_once at the top of all the admin controllers, so
Code:
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once APPPATH.'libraries/admin_controller.php';

class Home extends Admin_Controller {

    function Home()
    
    {
        parent::Admin_Controller();
        $this->auth->validate_admin();
    }

    function index()
    {}
}
is there a better way to autodetect the access of controllers/admin or something, and then load that controller right after the controller class gets loaded? would hooks be the way to go? Autoload doesn't work for this, and i don't want to use the MY_Controller method, as i don't even want the admin functions loaded unless they're accessing controllers/admin (plus i may wish to use MY_controller for another purpose)

thx

cc
#7

[eluser]OwanH[/eluser]
Hey commandercool,

I would actually recommend that you continue to do what you've already tried, i.e. add a require_once at the top of all the admin controllers. As you've noticed the Autoload wouldn't work and neither would the hooks feature.
#8

[eluser]simshaun[/eluser]
Thanks for that code commandercool.

I was wondering how I'd go about doing that.
#9

[eluser]xwero[/eluser]
I have some issues with Extending controllers because of the inflexibility, you can only extend a class from one parent class. So i use hooks most of the time and because you store the controllers in a subfolder it can be used as a trigger.
Code:
function init()
{
   $CI =& get_instance();
   $RTR =& load_class('Router'); // needed because the uri segments don't know which segment is the directory
   switch($RTR->fetch_directory())
   {
      case 'admin':
         // put cool stuff here
         $CI->auth->authenticate(2);
         $CI->nsite->depth_nav('Admin', 'home/');
         break;
   }
}
You then call the function in a post_controller_constructor hook or if you need to add more data to a certain class you can create a hook inside the controller.
Code:
class Home extends Controller
{

    function Home()
    {
       parent::Controller();
       $EXT =& load_class('Hooks');
       $EXT->_call_hook('in_controller_constructor');
       $this->auth->validate_admin();
    }
}
#10

[eluser]Phil Sturgeon[/eluser]
I answered a similar question about admin controllers in another post Auto including data in my view and as for the layout of your admin files, put one admin.php controller (extended from Admin_controller of course) in each module, then chuck the following routes in like on the post "matchbox and that old admin folder question".

Quote:$route['admin/([a-z]+)/(:any)'] = "$1/admin/$2";
$route['admin/login'] = "admin/login";
$route['admin/logout'] = "admin/logout";
$route['admin/([a-z]+)'] = "$1/admin/index";
$route['admin'] = "admin";




Theme © iAndrew 2016 - Forum software by © MyBB