Wednesday 18 March 2009

Basic CodeIgnitor Notes

If you write code then you may be familiar with this situation.

You have a small project that you write in the quickest possible way to meet a deadline and maximise profit.

It then grows and grows. At this point you are seeing the error of your ways and you should be using Object Oriented Programming and a bettter 'Framework'. Now have streams of spaghetti code, made from many copy and paste moments. The main problem with this is that changes to one bit of code and many other pieces may need to be changed or the knock on effects considered.

It's time to switch to a MVC framework and using someone elses rather than you're own will save time.

For the project I'm about to start helping on soon they use code ignitor, so it'd seem like a good time to have a look at their framework.

Here's some of the Basic pointers I picked out;

>> classes will extend Controller to use all the properties of this masterclass.

>> class names should be the same page names and can be called up from URL
/CodeIgniter/index.php/blog/
-> this will load the function 'index' in the blog class
->-> we could call up the function 'do_this' with the uri /index.php/blog/do_this/

NOTE: we could get rid of index.php through the .htaccess file to make cleaner URL's

>> if we're making a constructer ( same names as it's class ) remember that it will overwrite any constructer in the parent class. so we must call the parents constructor first . ie parent::Controller();

No comments: