What is MVC Architecture? Why Use it?

So you have been coding applications for a while and now you are facing an issue with debugging…

You are taking too much time to develop and deploy your application to production server..

You are ready to take things to the next level, which means, you want to develop and deploy applications faster, debug the applications quicker and without tampering the UI of the application.

Yes, i know it. I feel your pain.

Back in the day in the college, i was asked to develop an attendance management system for my college.

It took my 6-8 months to develop it because i used to plain old sequential programming approach with functions scattered everywhere.

No matter how much I tried i wasnt able to organize things. Although everything worked fine.

This is where i looked at frameworks which enabled to do rapid application development, in short, RAD.

…and all frameworks had something in common…

It looked somehow organized and as i glanced through the documentation i came across the term, MVC.

So What is MVC?

As per the official definition, Model-view-controller (MVC) is a software architectural pattern for implementing user interfaces.

It divides a given software application into three interconnected parts, namely Model, View, Controller.

Each of these components are built to handle specific development aspects of an application.

MVC is one of the most frequently used industry-standard web development framework to create scalable and extensible projects.

It makes your development so much easier even if you have the most complex of COMPLEX of requirements you will be able to handle the the look and feel as well as the logic of the application easily and efficiently.

Yes, no more days where you will pull out your hair and think, “WTF, did i write?”.

I have had these moments when i was developing my final year engineering project, Deeptrawl, an intranet based search engine.

so lets go deeper…

Components of MVC

Model: The Model component represents all the data related logic that the user works with, like the data that is being transferred between the View and Controller components. Basically, all the database related queries comes here, so you are not messing those queries along with the design of the application like the way you may have used to do before.

View: The View component is used for all the User Interface of the application. I would say these as the templates for the application, which means the HTML/CSS/jQuery and all front-end engineering codes come here. So if there is a slight change in the design you dont have mess around with the logic of the data.

Controller: Controllers as the name sounds “controls” what model to use and what view to display to the user, it collects all the incoming data initially before communicating with the database, meaning, this where we do form validations, user login verification (after getting some info from the database, ofcourse).

To put things into perspective and perhaps more clear…


Depending on the platfor you choose to develop on, the MVC architecture could differ from each other, but it will always serve the same purpose as i have mentioned in this blog post.

In upcoming blog posts, i would discuss about each of these implementation for a few platforms i like to develop on, so stick around for more good stuff.

Thank you for stopping by and reading this article. Let me know your thoughts in the comments, below.

Later. Cheers.


How to Upload files Using CodeIgniter Framework

Uploading files is one the most common functionalities you will see in most web applications.

Manual configuration and initialization of a file upload is quite tedious but with a framework alot of work is reduced to help develop application real quick.

Codeigniter framework provides a descent and efficient way to do this

The file upload library included in CodeIgniter is very simple to implement and highly configurable.

In this blog post I’m going to show you a basic implementation of it specifically for beginners.

Upload files Using CodeIgniter Framework

Just like for any framework, CodeIgniter follows the MVC Architecture.

Model: Handles the Database Queries

View: Handles the User Interface for the User

Controller: Handles the information to be showed to the User.

Step 1: Setup the View

Firstly, to upload a file we need to prepare a simple form view with an input field to upload a file.

<form action="" method="POST" enctype="multipart/form-data" >
    Select File To Upload:<br />
    <input type="file" name="userfile"  />
    <br /><br />
    <input type="submit" name="submit" value="Upload" class="btn btn-success" />

Please Note:

  • We have used ‘enctype’ attribute (means ‘ENCode Type’) with a value of “multipart/form-data” in ‘form’ tag, which tells CodeIgniter that, this form will contain a file upload control.
  • A file browser control is added by specifying type=’file’. This is the main control where user will be able to select a file from his local computer. By default user will be able to select single file. But if you wish to facilitate multiple files on your web application, you can additionally use “multiple=’multiple’” attribute in this tag. This will do the trick well.
  • When uploading files using CodeIgniter the “name” attribute should always be userfile.

Step 2 : Define File Configuration.

Once a file is uploaded, we let out our server-side codes to kick in and configure the uploaded file.

First , we will need to make a configuration array.

This will include the basic settings for file upload like upload path, maximum size, allowed file types etc.

You will need to initialize different configuration arrays for different upload forms.

If the file upload of your application works different from each other, you are better off creating the configuration array in the respective controller.

In other case, where if the file upload of your application works exactly same for all file uploads, then you can specify the configuration in ‘application/config’ directory and load when needed.

$this->config =  array(
                  'upload_path'     => dirname($_SERVER["SCRIPT_FILENAME"])."/files/",
                  'upload_url'      => base_url()."files/",
                  'allowed_types'   => "gif|jpg|png|jpeg|pdf|doc|xml",
                  'overwrite'       => TRUE,
                  'max_size'        => "1000KB",
                  'max_height'      => "768",
                  'max_width'       => "1024"  

Step 3: Loading CodeIgniter File Upload Library

CodeIgniter has a lot of helpful libraries that we can use for rapid application development.

Like said, file upload can be messy with Core PHP, depending on the complexity.

The CodeIgniter File Upload Library, makes this a lot easy and the configuration array you made above will be used as the settings for the library to function.

So we’ll load the library and use the do_upload() function to upload the file, using the settings specified in the configuration array.

$this->load->library('upload', $this->config);
    echo "file upload success";
   echo "file upload failed";

If the code above returns any error, you can show the error messages using “display_errors()” function of the library.

After successful file upload, CodeIgniter returns an object that has all the properties of the uploaded file for further usage, for example, inserting a record in database, making a thumbnail etc.

The final result would look like below.


Thank you for reading till the end of this post. I hope i was able to help you out with uploading a file using CodeIgniter.

Let me know your comments, thought, opinions or any problems if you are facing with CodeIgniter File Upload. I’ld be happy to help you out.










Inmotion OR Bluehost? Which One is The Best

One of the first things that comes to mind when thinking of choosing a hosting platform for your blog, is which one to go for?

Which hosting platform would be secure and reliable on the long run?

Since you are just starting out, you really don’t want to blow all your money on a hosting platform, right?

Well this blog post, is going to compare the two leading players in the shared hosting industry.

Inmotion OR Bluehost? Which One is The Best

When it come to choosing the right one among Inmotion Hosting & Bluehost, I would go ahead and say without a shadow of a doubt, that it is Inmotion.

But dont take my word for it, lets have a look at it.

A simple Google Search for Bluehost features will give you this link: https://www.bluehost.com/hosting-features

This URL has all features Bluehost talks about. Quite frankly, those features really don’t matter when you compare the hosting features and package available at Inmotion.

For Starters, Inmotion hosting uses SSD Storage for their hosting platform, that all by itself proves that they are faster than Bluehost which fails to mention anything about their Web Hosting Infrastructure.

I have worked with Bluehost & Inmotion for as long as a decade.

Ever since i started dabbling with websites and web development.

The company i used to work for had a reseller account from Bluehost.

Often times our customer’s website would go down without any prior notification from them.

The most common problem we faced with Bluehost is with emails.

Email hosting with Bluehost is a freaking nightmare.

This really did cause a problem to our brand image at the time.

Their support would take hours on top of hours to resolve any issue reported to them.

Now i really don’t to go on talking about a hosting service that made my life a living hell, so if you are interested I would like to redirect you to this Bluehost Review which breaks down in detail about their service.

Let me share with you a glimpse of the hell i was dealing with.


I got 16 of these emails on a Friday, a weekend in Oman and then i get the below mail which made me go WTF.


Inmotion Hosting

When i launched this blog and couple other websites, i was skeptical about Inmotion because i have never seen their ads as much as i have seen Bluehost.

I have never heard of anyone promoting or suggesting it as a hosting service, on the flip side, many entrepreneurs like Pat Flynn at smartpassiveincome.com (Huge fan) were promoting Bluehost like its the best thing ever.

Inmotion does cost alot more than Bluehost which is why it is so much better and really alot less painful to deal with.

I was impressed with Inmotion hosting’s support that i decided to take my “hosting relationship” to the next level by being their reseller for offering their service to my web hosting clients.

I gotta say this and am not exaggerating, i have never lost a single a client and neither have i heard anyone facing any issue with their hosting or emails.

Inmotion Hosting turned out to be the best investment i had ever made.

Now let me give some facts about Inmotion based on my experience. I don’t want to copy paste their features list over here and makes this page long. Thats not how i roll here.

  • WordPress hosting with Inmotion gave me an additional layer of security in the login section without using any extra plugins. It provides a security feature to block the IP address temporarily for an hour, if the login failed more than 5 times.
  • SSD Storage, meaning faster data retrieval and faster page load time. Good for SEO.
  • Never faced any issue with emails, including my clients.
  • Never had a downtime, including my clients.
  • Prompt notification before a server upgrade or maintenance.


My Verdict: Inmotion Hosting

Based on my experience with both the platforms, i definitely recommend Inmotion Hosting as your web hosting provider.

My experience with Bluehost was not good at all and there are many people who feel the same way as I do.

When it comes to Inmotion, the price is quite higher than Bluehost but they really do deliver for it and at the end of the day it worth it, on the long run.

I have been a customer and an affiliate with Inmotion Hosting since, 2011 and prior to that with Bluehost.

I have done my best to give you my opinion based on my experience with each of them.

Inmotion Vs Bluehost

This banner has my affiliate link in it, so if you were to make a purchase and get started with Inmotion, it would be a huge support for me. 🙂

Thank you for reading this blog post. Let me know your experience with your hosting provider in the comments below.