Hi there Ziffers
After Wil's rousing call to arms this morning for release 1.6, Jack
Sleight and I are happy to say that the newly accepted proposal for
Zend_Db_Table_Plugin is now in the incubator, ready for those
adventurous souls who like to mess with shiny new components. Please
be aware that it really is in its alpha stage, and no unit tests or
documentation exist outside of the proposal.
With that disclaimer out of the way, I can say the plugin architecture
is relatively stable and we're looking for feedback and bug reports
from anyone who can spare the time.
Essentially the plugin architecture allows you to attach observers to
Tables, Rowsets and Rows, and has hooks for pre/post operations in
each component as appropriate:- pre/Post init, fetch, save, insert,
update and delete. The row component also has hooks to allow your
plugin to act as an intercepter for getting/setting column values as
well, so you can now write modular plugins to take care of encoding/
decoding values on-the-fly, write auditing plugins, and a whole range
of fun stuff.
For those who haven't yet seen the proposal, you can find it here:-
http://framework.zend.com/wiki/x/pJw
Here's a quick code sample to get you started:-
Your bootstrap
============
// The plugin architecture follows a similar strategy to that of
Zend_Form and others...
Zend_Db_Table_Plugin_Broker::addPrefixPath('My_Plugin', realpath('../
application/default/models/My/Plugin'));
Zend_Db_Table_Plugin_Broker::registerPlugin('Test');
Your plugin
============
<?php
class My_Plugin_Test extends Zend_Db_Table_Plugin_Abstract
{
public function preInitRow(Zend_Db_Table_Abstract $table)
{
echo 'preInitTableRow...';
// $row->foo();
}
public function setColumn(Zend_Db_Table_Row_Abstract $row,
$columnName, $value)
{
return $value . '-test';
}
}
Your controller/action
============
// My_Test is simply an instance of Zend_Db_Table_Abstract, with a
table $_name defined. Replace it with real values
$myModel = new My_Test(array(
'db' => $this->_db
));
$row = $myModel->createRow();
$row->name = 'Plugin test'; // $row->name should now be 'Plugin test-
test'
$row->save();
Documentation and unit tests are due to be written in the following
fortnight - just in time for inclusion for 1.6 if we can help it :)
Look forward to your thoughts - cheerio!
--
Simon Mundy | Director | PEPTOLAB
""" " "" """""" "" "" """"""" " "" """"" " """"" " """""" "" "
202/258 Flinders Lane | Melbourne | Victoria | Australia | 3000
Voice +61 (0) 3 9654 4324 | Mobile 0438 046 061 | Fax +61 (0) 3 9654
4124
http://www.peptolab.com