Magdy Medhat's Blog

Experience Shared in a few words

Posts Tagged ‘Backend’

Before Starting a Codeigniter Project

Posted by Magdy Medhat on 07/01/2012

Good evening folks!

How is your Codeigniter progress? Today I’d like to share a few tips with you in order to actually start a Codeigniter project!

First thing, concerning the disturbing feature of Codeigniter (removing the index.php from the URL) if you’d go for a localhost server (i.e. WAMP Server) then make sure to uncomment the “LoadModule rewrite_module modules/mod_rewrite.so” command at the httpd.conf file (found at your apache sub menu from your WAMP server tray icon at the taskbar).

Secondly, if you are working online with FTP connection make sure you modified the permissions of your uploads folder to allow write rules.

Now if we took a look at some of the HTML templates we’d find that there is a common header, footer and a sidebar at each page of your template and what really differs is a part of the page which we can call the content of that page. So basically we’d split our pages into a header, footer, a sidebar (sometimes we combine it with the header) and a number of content views. It became easier this way because each time we want to display a page, we would simply load the header view, load a content view then load the footer view.

As I’m really interested in the development part of the process, I sometimes whether buy/download the most suitable HTML Template online, or have a designer partner working with me on it, but at most cases there exist those tweaks that you need to make, and that’s when you need some basic knowledge of both CSS and Jquery (Javascript) for example; if you need to move a button a little to the left, use some Jquery plug-in, use AJAX or add form validation.

When we start collecting the requirements we must build a clear and comprehensive use cases that describe exactly the functionality that the client wants. Then we design the database structure. One important lesson I learnt about naming your columns at your database is always have them named uniquely because if you are going to run a few Join queries, it will seriously cause you a lot of pain. For example if you have a table for teachers and another table for students and both have the column “name”, then simply if you tried a select all query with joining both tables you would get 2 columns labeled “name”. And you will have to rewrite your query in order to add some alias for each “name” column to distinguish a one from another. A solution for this problem would simply be; concatenating the table name before each column name with an underscore.

It’s obvious to know that any web application is divided into two parts; frontend and backend. The frontend is actually what your client wants the user to see, this is where you need your designer friend to design the HTML template that will satisfy the client needs. The backend is also known as the admin panel and this mainly does not change from a project to another; you just stick to an admin panel template that you really like and find suitable for different cases (you can find some awesome admin templates at Google). The admin panel should be easy to customize, with a little knowledge of (HTML, CSS and Jquery) you get to copy some elements and change their order inside a container or a grid to produce dynamic different pages that fit your case.

So as we were just saying, we got a frontend and a backend, this separation should happen in each of our main folders (Includes, Views, Controllers and Models).

Includes

We will have 2 inner folders; frontend and backend and each one would contain the CSS, JS and IMG folders for the required HTML Template.

Views

As stated, we will have 2 inner folders; frontend and backend and each one would simply contain a header, a footer and a number of contents. Note that we will need to change the included location of any CSS, JS or IMG files found at all the views to the new location at the Includes folder.

Controllers

Well, I go for a controller for each one of our sides, which means we would have two controllers; a frontend one and a backend one, and of course each one manages the functionality of its part.

Models

Since we make a model to deal with the database, and it’s actually the same database for both sides, I don’t really use more than one model, especially when there are some common queries between both sides.

Finally, all we are missing now is how often would you need to call Codeigniter helpers and libraries and which of these is mandatory? When do you know that you want to make your own helper or library? All these and a lot more best practices are possible to gain when you start building some projects with Codeigniter.

I guess that’s it for now, I hope you guys liked it, until the next time, go find your preferred admin template and build your first Codeigniter Project 😉

Posted in Codeigniter, php, Web Development | Tagged: , , , , , , , , , , , , , , , , , , , , , , , | Leave a Comment »