开发者

codeigniter, uri routing and subcontrollers

开发者 https://www.devze.com 2023-02-06 11:43 出处:网络
not sure how to do this... i have an controller name admin- and i want to use the controllers in a subfolder as \"sub\" controllers

not sure how to do this... i have an controller name admin- and i want to use the controllers in a subfolder as "sub" controllers

i.e when a user visits mydomain.com/admin they are redirected if they are not logged and if they visit mydomain.com/admin/customers they are also redirected but the actual customers class is stored in controllers/admin/customers.php

i want the admin controller to handle the check if logged in and add on the header template?

how can i route this?开发者_StackOverflow


If I understand you correctly, try extending the base controllers

<?php

class MY_Controller extends Controller
{
    function __construct()
    {
        parent::__construct();
        if(!$this->auth->logged_in()) 
        { 
            redirect('login'); 
        }
    }

}


class Customer extends MY_Controller {

// if the user isn't logged in they will be redirected

}

I cite once again Phil Sturgeon

0

精彩评论

暂无评论...
验证码 换一张
取 消