Welcome Guest, Not a member yet? Register   Sign In
CMS best practice on CI
#11

[eluser]Mr. Pickle[/eluser]
1. REROUTING
You need to think the other way. What the user accesses IS the url.
Start with the url that the user visits (requests, or access like you said) and from there route your way to the controller you want, not the other way around around Smile

So, the user accesses/requests admin/news/add (because this is the url you want)
Codeigniter thinks it should be interpreted like this:
controller: admin
method: news
param1: add

What you want is:
controller: news
method: add

So reroute the url like this
Code:
$routes['admin/news/add'] = 'news/add';

Mind that rerouting is NOT redirecting. The user will still see /admin/news/add.
Of course the example above is pretty static, you can make it more dynamic (see earlier posts)

2. ADMIN CONTROLLER
Yes there is a pretty workable way of doing this.
I would suggest this:
1. rename the file admin.php in controllers to Admin_controller.php
2. move the Admin_controller.php file from /application/controllers to /application/core/
3. change this file so that the class is called Admin_controller and put all admin functions in this file:
Code:
<?php
class Admin_Controller extends CI_Controller
{
    public function __construct()
    {
       parent::__construct();
    }

    public function is_logged()
    {
        // ....
    }
    
    // all the other shared admin functions go here ....
}
?>

4. Make all the ADMIN controllers extend the Admin_controller. So for example the news controller (/application/controllers/news.php:
Code:
<?php
class News extends Admin_Controller()
{
    public function __construct()
    {
       parent::__construct();
       // you can for example load $this->is_logged()
       // here if you want to have this function run automatically.
    }

    public function add()
    {
         // ....
    }    
}
?>

Note that now the Admin_controller is extending CI_Controller and the normal controllers extending the Admin_Controller.
If you also have controllers outside the admin area make sure they extend CI_Controller.



Messages In This Thread
CMS best practice on CI - by El Forum - 10-22-2012, 05:23 AM
CMS best practice on CI - by El Forum - 10-22-2012, 05:41 AM
CMS best practice on CI - by El Forum - 10-22-2012, 05:48 AM
CMS best practice on CI - by El Forum - 10-22-2012, 05:56 AM
CMS best practice on CI - by El Forum - 10-22-2012, 05:57 AM
CMS best practice on CI - by El Forum - 10-22-2012, 05:58 AM
CMS best practice on CI - by El Forum - 10-22-2012, 06:58 AM
CMS best practice on CI - by El Forum - 10-22-2012, 07:06 AM
CMS best practice on CI - by El Forum - 10-22-2012, 07:15 AM
CMS best practice on CI - by El Forum - 10-22-2012, 09:24 AM
CMS best practice on CI - by El Forum - 10-23-2012, 02:31 AM
CMS best practice on CI - by El Forum - 10-23-2012, 04:08 AM
CMS best practice on CI - by El Forum - 10-23-2012, 04:49 AM
CMS best practice on CI - by El Forum - 10-23-2012, 04:55 AM
CMS best practice on CI - by El Forum - 10-23-2012, 05:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB