Creating an ORM for PHP is not an everyday task but writing one is a good way to improve your PHP skills, especially if you use some of the additional features PHP 5.3 adds to the language. There are many excellent ORMs (Object Relational Mappings) already in existence and for a real-world project it would probably better to use one of these, but this tutorial uses the task of creating an ORM as a way to take a look at applications for some PHP 5.3 features.
Posts by: Peter Verhage
Learning PHP 5.3 by writing your own ORM January 11, 2010
Surviving a Plane Crash April 23, 2009
NU.nl is a well known news website in its homeland, The Netherlands, and is actively expanding into other countries. On an average day NU.nl will serve up 7 million page views; peak traffic days are more than triple that number. In short, it is one of the top 10 Dutch web sites in terms of traffic. Previously, on our corporate blog, Erik Snoeijs discussed the technologies deployed while building out the back-end of NU.nl in is article "NU.nl; the back end”. In this article we want to look at the front end that we architected for NU.nl, and how we designed the system to handle both regular traffic and peaks.
ATK's hidden gems, part 1 November 1, 2007
ATK contains lots of hidden gems. Most of them are hidden because they are undocumented or because they are only documented in the API docs (which nobody seems to read...). In the past few years we've tried to improve the documentation for ATK. We've created a Wiki with lots of how-to's, the "Pizza Guides", a demo application and improved the API documentation. However there are still some features of ATK nobody seems to know about. In my next few blogs, starting with this one, I will write about some of them.
Using list columns for atkManyToOneRelations
By default the atkManyToOneRelation displays the descriptor of the destination record in the record list. However, sometimes your descriptor consists of more than one field which you would rather show in separate columns. The benefit of showing them in separate columns is that it's more clear to read and that it allows you to sort and search the list using these fields. What many people don't know is that the atkManyToOneRelation supports this out-of-the-box.
To use this feature you add an atkManyToOneRelation to your (meta-) node the way you would do so normally. After the relation has been added you can call the addListColumn method on the relation object to register the destination fields you want to see in separate columns in the record list. That's it! If you now look at the record list you will see a column for the relation itself and next to it one or more columns for the registered list fields. If you want to make these fields searchable you need to add the AF_SEARCHABLE flag to the attributes they represent in the destination node.
Sometimes you only want to show registered list columns and not the column for the relation itself. If that's the case you need to add the AF_HIDE_LIST flag for the relation and you should call setAlwaysShowListColumns(true) on the relation object. If you now look at the record list you will see that it doesn't contain the relation column anymore but the list columns are still there.
A small code example:
1 2 3 4 5 6
$attr=$this->add(new atkManyToOneRelation('manager_id', 'employee.manager', AF_OBLIGATORY|AF_HIDE)); $attr->addListColumn('firstname'); $attr->addListColumn('lastname'); $attr->addListColumn('city'); $attr->setAlwaysShowListColumns(true);
This will show the manager relation as 3 separate columns in the record list which allows the user to filter the list by manager firstname, lastname and/or city.
More next time.