0

I started working on a project which should have admin panel and frontend and I want to use CodeIgniter framework on client request. But the problem is I am not able to understand how to start the project as mentioned above. I want folder similar to the image shared

enter image description here

1
  • You mean only authenticated user can access "admin" zone? If it is correct, you should have a Admin_controller in application/core. Constructor of this controller checks permission of current user and allows / denies access. Commented Aug 24, 2018 at 14:53

2 Answers 2

1

Besides the Admin_controller (for separeted security rules), for better organization, it's good to use some extension like this one:

HMVC: https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/src

With this you'll be able to that this type os structure:

enter image description here

URLs

http://awesome.site/public_controller

http://awesome.site/*module_name*/*controller_inside_module*

http://awesome.site/admin/login
Sign up to request clarification or add additional context in comments.

Comments

1

Try using Codeigniter's session functionality to authenticate the user and his role (e.g., "admin", "customer", etc)

Then add a constructor like this to every controller (this is just an example)

class Admin_only extends CI_Controller {

    public function __construct()
    {
        parent::__construct();

        if( !isset($this->session->userdata['logged_in']) || $this->session->userdata['logged_in']['user_type'] != 'administrator' )
        {
            // you're not welcome here
            redirect('welcome/access_error');
        }

    }

The __construct() is run every time anything within the controller is accessed.

See how in my example (there's cleaner ways, but this will definitely work), I'm constantly checking if the user is logged in AND if the user is an administrator (actually I'm checking the opposite... logged out OR not administrator, but it's pretty much the same thing logically) and if the check fails, the user is redirected away from the controller.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.