Step 1: First contact – What is MVC and what is CodeIgniter

Created at: November 7, 2014; Last update: April 24, 2017

(created: November 14, 2014; last update: January 12, 2015)

OK… You are a bit knowledgeable regarding PHP, you are proficient at creating spaghetti code, and you know a thing or two about OOP. Then, someone comes to you and says something about MVC. You say “Riiiiight…”, and do your best not to betray the fact that you don’t know a darn thing about what MVC is.

So you go to Wikipedia and write “MVC” in the search form.

“Model–view–controller (MVC) is a software architectural pattern for implementing user interfaces. It divides a given software application into three interconnected parts, so as to separate internal representations of information from the ways that information is presented to or accepted from the user.”

“Wow… Why didn’t I think of that?”, you say to yourselves. After a bit of reading you find out that:

A controller can send commands to the model to update the model’s state (e.g., editing a document). It can also send commands to its associated view to change the view’s presentation of the model (e.g., by scrolling through a document).

A model notifies its associated views and controllers when there has been a change in its state. This notification allows the views to produce updated output, and the controllers to change the available set of commands. In some cases an MVC implementation might instead be “passive,” so that other components must poll the model for updates rather than being notified.

A view requests information from the model that it uses to generate an output representation to the user.

After that you can absolutely say “YES! I KNOW WHAT MVC IS!!!”. But how can you implement something like this in PHP? The easiest thing, you might say, would be to create your own MVC structure and start from there (a great tutorial about that would be PHP Academy’s). But after a lot of tries and fails you say: “F*** IT!” and look for a well established MVC framework.

If you do a Google search you will find a lot of alternatives. But I will assume that if you got to this page, you’ve found CodeIgniter to be of your liking.

So, download a fresh copy of CodeIgniter, put it inside your server’s public folder (or wherever you want it to be), and see if all went well.

Of course you can also download CI 2.2.4, but I would advise you to install version 3, even if it is in development stage.

For this tutorial we will put it inside htdocs (I will suppose that you have XAMPP installed).

Now, if you visit “http://localhost” you should see your new CodeIgniter “site”…

6 thoughts on “Step 1: First contact – What is MVC and what is CodeIgniter

    1. avenirer Post author

      No… It doesn’t. MY_Controller should be accessible by everyone, so there’s no need to load the library if we do not use it.

      Reply
  1. Nuri Sanuri

    Hi,
    I try your tutorial. But, when I access http://localhost/myapp/user/login login_view cannot display (blank).

    And then, I try to change the login() content just like this
    public function login() {
    $this->load->helper(‘form’);
    $this->render(‘user/login_view’);
    }

    It’s still blank.

    But, if I change $this->render(‘user/login_view’) with $this->load->view(‘user/login_view’), that’s can display login_view form.

    I follow tour tutorial http://avenir.ro/authentication-system-with-ion-auth-and-ci3/lets-install-ion-auth-library/

    Reply
    1. avenirer Post author

      That is most likely because you didn’t follow all the steps up until that episode 🙂

      Reply
  2. Khairul Fajeri

    I recommended you to create other tutorials like “CREATE A CMS USING CODEIGNITER 3”, maybe “BLOG”, “SOCIAL MEDIA”, or anything little complex tutorials. because you are awesome !, that’s just suggestion !.
    I am from Indonesia, i very interest to learn CI. good luck..

    Reply

Leave a Reply

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

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