freerider

Laravel 4 Model Events: Dynamicaly populate columns on insert/update

When I create some sort of admin panel, I usually want to know not only when a user created or edited an item (post), but also who that user was.

Considering this, I always add two additional columns to my tables: created_by and updated_by. This, along with the timestamps from Laravel, is the best way to keep track of latest changes of a database record. Continue reading

multi-level menu

Multi-level menu in PHP – how to do it without killing yourself or the database in the process

Well. It’s been a long time since I’ve written a post. I was busy learning Laravel… Currently, I am trying the framework by working on a CMS, and, again, I have arrived at the phase of menus. And by “menus”, I am refering to multi-level menus. In the past I have found ways to bypass this dilemma, but now my time allowed me to dive into it. Continue reading

Codeigniter – Convert an array to object

I usually use the results that come from the models as objects (not as arrays). However, there are moments when I need to work with the results before sending them to the view. In this case, getting the results from the model as an array is preferable. But, when I send them to the view, I would like to work with objects. So now I need to convert the array into an object. Continue reading

How to use a “Cookbook” with Codeigniter

cookbookI was asked to do a review for Codeigniter 2 Cookbook, written by Rob Foster and published by Packt Publishing (to be honest, I actually asked to review the book to get it for free).

I haven’t managed to keep the promise of reviewing the book in due time, but suddenly I realised that every now and then I return to the book to uncover a new programming style that makes me say: “Ahaaa”. Continue reading

rules

Forms? Keep the validation rules inside the model

As always, when talking about forms we also talk about validation. For a long time I’ve validated the forms inside the controllers because it is fast and simple – no more browsing between files.

But after a while you find yourself having a controller which is becoming more complex and bigger. So why not keep at least the validation rules somewhere else? Continue reading

models

Codeigniter: My MY_Model or “How not to repeat yourself”

Often times I find myself doing the same queries over and over again for each table used by an application. This is why I needed to create an “universal” model in order to avoid repetition. Codeigniter lets you do that by allowing you to create a “MY_Model” inside the core folder of your application. Continue reading