Building a Custom CMS — Using Codeigniter
By: Phillip Hughes
Tags: MVP, Codeigniter, Codeigniter Development, Laravel, Cms Development

Many projects or products nowadays require you to manage data on a day to day basis. With many “off the shelf products” helping you do this. What happens if you need to build a custom CMS for your project? Tailoring the solution to work exactly as you would like. There a so many things that you could or should consider. Cost, skill availability, use an existing framework? Develop it from scratch? Which underlying Operating System to use? The list goes on. I had a similar task when building a custom CMS a few years ago. For our project I used the Codeigniter framework. This blog is going to run through why I chose Codeigniter and how I found developing the custom solution.

Building a Custom CMS

A few friends and I decided to start our own business which was to build a mobile app for travelling football fans (The business is still going, you can find our website here). Our main requirement was to be able to collate and record information into a central database which the mobile apps could pull data from. We made the decision to build a CMS which any of us could login to and manage the data.

As we were funding the business ourselves we had to keep costs to a minimum. With my experience working in the web hosting industry, I suggested we go with a Cloud VM which can be cheap. Pretty reliable and easy to scale up if needed. I opted for a Linux VM running Ubuntu to reduce costs further. Linux requires very little hardware to run smoothly. Even though I was predominately a programmer that used Microsoft technologies. I kept away from using Windows as you have to pay a license fee each month and need more hardware resource to run Windows. Increasing the monthly costs two fold.

Picking The Framework

Deciding to use a Linux VM had already swayed me to which programming language to build the CMS with. I had chosen to use PHP. Luckily at the time I had done a fair bit of programming using PHP in my day job. I had also decided that this time I wouldn’t build something from scratch and use a framework to speed up development time.

I had been looking at a few frameworks and had narrowed it down to two. At the time Zend Framework and Codeigntier were the two main players in MVC frameworks, built using PHP. After spending a day or two playing around with each framework, I decided to ditch the idea of using Zend. Even though at the time it was the more popular and powerful of the two, I just found it to over complicate things. I wanted to get the CMS out the door ASAP. The framework needed to be simple to use. Allowing me to get each section of the CMS live in the quickest time possible.

Working With The Codeigniter Framework

Straight away I found the Codeigniter framework easy to use and really quick to setup. At it’s basic level you download a zip file, extract the contents and upload to your server. It is a case of then editing two file to setup your website and database connection. That’s it. Result! Even increasing the security of your website is relatively straight forward with Codeigniter. The more experience I get in software development the more conscious I am of implementing security first and foremost. Sadly, I’ve had to much experience in trying to lock down systems that are already live. This give me achy balls. Security around the implementation of or your solution should be done first and foremost. Sounds boring, trust me it will save you time, money and a lot of pain in the long run.

As Codeigniter is built using the Model-View-Controller architectural pattern, which I have a bit of experience using the MVC pattern from my ASP.Net background (I won’t bore you by going into the MVC pattern). Within an hour I had a few pages knocked together displaying some basic information I had entered into our new database.

Simple As 1,2,3 (Files)

To start the ball rolling. I began by creating a “dashboard” screen which would be the CMS’ homepage. It was as easy a creating 3 files. One file called dashboard.php in the controllers folder which acts as the “brain” when a user browse to that page. A file called league_model.php in the models folder which retrieves and stores data from the database. Finally a file called dashboard_index.php in the views folder. This file contained the HTML to render the page and display the information about each league. That’s it job done! Well not as an MVP, as a proof of concept it worked. Building a Custom CMS for our little business was possible. We would soon have a central point that we could start developing our products with.

Another thing I liked about Codeigniter is the built in libraries that it comes packaged with. From form validation all the way up to security and session management. You can import the library using one line of code, so you only load what you need on each page of your website. Another benefit is it allows you to again just focus on what you are trying to achieve in managing your data.

Design and UX

Now as a programmer I’m not blessed with the best UX skills. Even though I was pretty good at Art & Design at both school and college. I always try to improve the look and usability of software I develop. It can be a challenge and I find it difficult getting the design out of my head and implemented. Because of this I decided to the Bootstrap library as my design toolkit to style the CMS. Using Bootstrap not only gives a consistent theme to a website. It has been designed to be “mobile first”. Which means we could use our CMS on any device.

It was fairly quick and easy to drop the Bootstrap library into the CMS. To make things easier I created my own template within the Codeigniter framework. Which would ensure any page within the CMS would load all the required styles or libraries in the page header. You then tell the template which view you wanted to display and this would get rendered in the main body of a page. To keep things simple and in keeping with the Codeigniter framework. I developed the template so I could pass in a list of which Javascript files I wanted to load for a particular page. Making sure each page only loaded what it needed (similar to the way Codeigniter allows developers to import libraries as and when required)

Challenges

Most of the setup and development during building a custom CMS was straight forward and I was able to achieve what I wanted from each page. As mentioned in the previous section. I built a custom way to load a Javascript file into each page. Codeigniter does have an in-built Javascript library which allows common jQuery functionality to be available. I struggled getting this to work.

Whether it was my lack of experience in using jQuery. Or a limited knowledge of Codeigniter. It could be I read the documentation wrong (Even though I went through it a number of times over the course of a week). No matter what I tried, I could not get the library to load.

When I originally started building a custom CMS I was using an older version of Codeigniter. So it could have been isolated to the version I was using. Either way it led me to use my own template to load specific Javascript files that used jQuery and the Bootstrap Javascript to achieve what I needed.

The only other small issues I had were resolved really quickly by using Codeigniter’s documentation. It is very comprehensive and with a bit of reading you should be able workout how to use the framework to meet your needs.

MVP Or ITB (In The Bin)?

As of February 2018 when writing this blog the CMS is still up and running. We started using it in October 2014. It has been over 3 years since the initial version was put live and it is still going strong. There has been some additional development and improvements over the years (As with all IT projects). I will be writing a few more blogs documenting what improvements we made. Utilising Codeigniter to quickly achieve what our business required.

I have a few more plans for our CMS. Firstly to upgrade the version we are using. Along with integrating third party API’s to help us collate the information into one single dashboard.

Thumbs Up or Thumbs Down

I would definitely recommend Codeigniter to anyone who is on a tight budget but needs a framework to build out their solution. I have helped a few people out with their websites over the past 18 months which have been built using Codeigniter and that hasn’t dampened my view.

Their are a few new kids on the blog in terms of PHP based MVP frameworks such as Laravel. Which if you are starting from scratch may be worth looking into. That said I still think that Codeigniter is the quickest to get up and running and the easiest for programmers to get to grips with.

If you would like to know more about the projects that I have used Codeigniter on. Or have any questions please get in touch. Cheers