I'm dealing with database containing of many tables, with many field prefixes (two first letters of every table), so when I have users table I cannot use "name" property ($user->name) but I can use: $user->us_name.
I's there a way to simplify things and set automagic prefix for every field of a table ?
You'd have to extend
Zend_Db_Table_Row
to accomplish this. Fortunately, ZF includes a_transformColumn()
method expressly for this purpose. But I'm getting ahead of myself. First, set up your table class. This assumes your database has a table called "foo_mytable":Next, create your custom Row class:
Now, you can do something like this (for simplicity, this example ignores MVC design ideals):
Assuming your table has a column named "us_name", this should work. I tested it myself. Note that in your custom table row, you might want to grab the table prefix from a config file. If you've got it stored in your registry, you could replace
$prefix = 'us_';
with$prefix = Zend_Registry::get('tablePrefix');
.I didn't know about _transformColumn(). I'm gonna hop on top of @curtisdf 's example.
I think you should override with this (not tested):
Using this, you won't need to store prefixes/table-names, as they are retrieved dinamically.