Step 1 – Create an admin area in CodeIgniter 3

Created at: January 22, 2015; Last update: October 30, 2015

Every respectable blog must have an admin area. In CodeIgniter there are a lot of methods to create such an area. In this tutorial we will simply make a directory named admin inside the controllers directory and also an admin directory inside the views directory.

So let’s get to work

First of all we create create the directories mentioned before.

Now we will create a controller named Dashboard (Dashboard.php)inside the application/controllers/admin directory:

As you can see, the index() method of the dashboard class will load dashboard_view which is loaded from the views/admin directory. For starters the dashboard_view.php will look like this:

After we’ve done all this, we must make sure that when someone goes to http://localhost/admin, he/she will be taken to the dashboard. To do this we simply add a route inside the routes.php file. Now, the file will look like this:

Also, one thing to note is that the Dashboard is extending Admin_Controller. In this tutorial I decided to follow Jim Parry’s example in creating more than one single MY_Controller. So, MY_Controller.php will look like this for now:

That’s it. We now have an admin area. In the next tutorial we will create the basic template for the dashboard’s pages and after that we will secure the dashboard.

25 thoughts on “Step 1 – Create an admin area in CodeIgniter 3

      1. fxf999

        it is because dashboard_view.php should be put on folder application/views/admin/dashboard_view.php instead of application/views/dashboard_view.php
        (previously i experienced the same problem Sojib because of following the view path from your tutorial, i think you need to edit it Sir Avenirer)

        Reply
  1. nanart

    Hello,
    first: excuse my english, i ‘m french 😉
    There is something wrong, or i don’t understand:
    You write: “Now we will create a controller named Dashboard (Dashboard.php)inside the application/controllers/admin directory:”
    and i see in the script’s title: “application/controllers/Dashboard.php”…
    What is the right way, please :
    /controllers/Dashboard.php or /controllers/admin/Dashboard.php ?
    Thanks

    Reply
    1. avenirer Post author

      Tu peux parler aussi in francais… Pardonne-moi. Tu dois creer le fichier dans “application/controllers/admin”.

      Reply
      1. nanart

        thanks.
        It’s the same for the next pages, we should understand :
        not: application/controllers/Dashboard.php
        but—> application/controllers/admin/Dashboard.php

        Reply
  2. bienchris

    Bonjour,
    j’ai suivi le tuto, c’est bien présenté. Merci.
    Mon souci c’est sur le “routes”, doit-on créer un répertoire development et un nouveau fichier routes.php dedans (application/config/developement/routes.php)? Pourquoi on n’utilise pas le routes.php dans le config.
    Je ne sais pas pourquoi aussi, car j’ai la page 404 quand je fais http://localhost/admin
    Bonne journé

    Reply
    1. avenirer Post author

      Tu n’est pas oblige a faire le “routes.php” dans le config/developement. Tu peux aussi le fair dat le config. Hmmm… it’s easier in english… Can you send me your application directory in a zip file at avenir.ro@gmail.com? Thank you.

      Reply
  3. sounder

    Hello, I have just installed codeigniter-3.0.3 but there is not “application/config/developement/” folder. There is only “application/config/”. There I have modified routes.php as your example. But i get error “404 file not found”.

    Files are in the right folders:
    – controllers/admin/Dashboard.php
    – views/admin/dashboard_view.php

    The only difference is that my base url is “http://localhost/codeigniter-3.0.3” (I have update config.php $config[‘base_url’] = ‘http://localhost/codeigniter-3.0.3/’;)

    What’s wrong?

    thank you

    Reply
    1. avenirer Post author

      Remove “-3.0.3” from the folder name… and from the config. Also, did you follow the tutorials from the previous series (http://avenir.ro/codeigniter-tutorials/)? Is not really required, but you need to have a viable installation of your CI framework. At least go from episode 1 to episode 7 🙂

      Reply
  4. Manveer

    For codeigniter-3.0.3 , you need to change one piece code of line in the file

    application/controllers/admin/Dashboard.php

    class dashboard extends Admin_Controller

    With

    class dashboard extends CI_Controller

    Reply
    1. avenirer Post author

      Woooow… Who told you that??? Don’t do that, pleaaaaaaase. Where did you get that idea from? Did you at least read the tutorials that were prerequisite for this series? Or you just want to seem professional?

      Reply
  5. Andy

    Got below Error Msg

    Message: touch(): Unable to create file sessions/ci_session4dc0e26a2bb79fc8a06893ce8fbd19b9e1974a0b because No such file or directory
    Filename: drivers/Session_files_driver.php

    Did I sth wrong?

    Reply
  6. Hao

    Hi,

    Thanks for your tutorial. I’ve followed your steps exactly, but I am stuck at displaying my admin page. When I visit http://localhost/admin, it displays the following:

    404 Not Found
    nginx/1.9.3 (Ubuntu)

    I am able to access http://localhost which displays Nginx welcome message. Could you kindly assist me on this?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

No spam? * Time limit is exhausted. Please reload CAPTCHA.