If the class is App_Db_Table_Abstract or i prefer My_Db_Table_Abstract and
you're using the autoloader in bootstrap it would map to
application/../library/My/Db/Table/Abstract.php. Assuming of course that you
have the the lib in the include_path.
e.g.
/**
* 1. Set the include_path to include application library path
*
* /base/public/index.php
*
*/
$base = realpath(dirname(__FILE__) . '/../');
$paths = array(
'.',
get_include_path(),
$base . '/library',
);
ini_set('include_path', implode(PATH_SEPARATOR, $paths));
/**
* 2. Set up autoload.
* This is a nifty trick that allows ZF to load classes automatically so
that you don't have to litter your
* code with 'include' or 'require' statements.
*
* /base/application/bootstrap.php
*
*/
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
/**
* 3. Now simply drop your custom class into appropriate folder.
* We'll call the class My_Db_Table_Abstract, so:
*
* /base/application/library/My/Db/Table/Abstract.php
*
*/
class My_Db_Table_Abstract extends Zend_Db_Table_Abstract
{
protected function _setupTableName()
{
parent::_setupTableName();
$config = Zend_Registry('config');
$prefix = $config->db->table_pfx;
$this->_name = $prefix . '_' . $this->_name;
}
}
Now you can use the class anywhere in your application and it will be auto
loaded.
More on the autoloader here
http://framework.zend.com/manual/en/zend.loader.html#zend.loader.load.autoload
A quick read of the quickstart is recommended too
http://framework.zend.com/docs/quickstart/create-a-bootstrap-file
Giovanni A. D. wrote:
>
> On Fri, Oct 31, 2008 at 11:07 PM, Rob Allen <[EMAIL PROTECTED]> wrote:
>> I would probably extend Zend_Db_Table_Abstract and automatically add the
>> prefix when setting up the table name. Something like this:
>>
>> class App_Db_Table_Abstract extends Zend_Db_Table_Abstract
>> {
> [...]
>
> hi,
> where would it be the best place to extend the Zend_Db_Table_Abstract
> class?
>
> I mean.. somewhere like application/../my_lib/app_db.php that you then
> include from the bootstrap file.. ?
>
> Thanks!
>
> bye,
> Giovanni.
>
> p.s.
> I've also finished your tutorial; very well done.. thanks for making that
> too!
>
>
--
View this message in context:
http://www.nabble.com/db-table-prefix-from-config-tp20268459p20301523.html
Sent from the Zend Framework mailing list archive at Nabble.com.