Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-15-2007, 12:02 AM
Junior Member
 
Join Date: Oct 2007
Posts: 16
Default Transform column names into camelCase?

I'm working on a project where the column names are in uppercase, with words separated by underscores.
Is there any built in option in Zend_Db to automagically have these column names transformed into camelCase when you fetch stuff?
For instance, if I'm fetching an object it would be nice to have $obj->userId instead of $obj->USER_ID.
Edit: And by the way, I'm using the Pdo_Mssql driver.

Best Regards,
Troxy

Last edited by troxy : 10-15-2007 at 12:59 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 11-05-2007, 10:05 PM
Junior Member
 
Join Date: Oct 2007
Posts: 16
Default

Okay, so you have to extend the Zend_Db_Table and Zend_Db_Table_Row.
The extended table class might look like this:
PHP Code:
class MyTable extends Zend_Db_Table_Abstract {
    protected 
$_name 'TABLE_NAME';
    protected 
$_primary 'ID';
    protected 
$_rowClass 'MyTable_Row'// Tell it to use your custom extended row class

And in the extended row class is where the magic occurs:
PHP Code:
<?php
class MyTable_Row extends Zend_Db_Table_Row_Abstract {

    protected function 
_transformColumn($columnName) {
        if (!
is_string($columnName)) {
            require_once 
'Zend/Db/Table/Row/Exception.php';
            throw new 
Zend_Db_Table_Row_Exception('Specified column is not a string');
        }
        return 
strtoupper(preg_replace('/(?<=\\w)([A-Z])/''_\\1'$columnName)); // Transform the camelCase into UPPER_CASE
    
}
}
And then you can simply use it like this
PHP Code:
$table = new MyTable();
$result $table->find(10);
$row $result->current();
$value $row->fooBar// The actual name in the table is FOO_BAR 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 11:28 AM.