In idea to write less I'm trying to extend default Zend ORM system. I mean if we get from Db some data via Zend_Db_Table we can later process this data using Zend_Db_Table_Rowset or Zend_Db_Table_Row classes. My idea is to use custom Factory class like this:
class Go_Factory {
const PREFIX = 'mule_';
/**
* get from database item by specified primary key
*
*/
public static function get( $class_name, $identity ){
return self::getDbTable( $class_name )->find( $identity );
}
/**
* well, there is a corelation between class name and represented by it table name in DB
* so let's get one from another
* return instance of Zend_Db_Table with defined _name and _rowclass parameters and
*/
public static function getDbTable( $class_name ){
$db_table_class = str_replace( "Model_", "Model_DbTable_", $class_name ) . "s";
$row_class = class_exists( $class_name ) ? $class_name : "Core_Model_Item";
if( !( class_exists( $db_table_class ) ) ){
$temp = explode( "_", $class_name );
$table_postfix = strtolower( preg_replace( '/([^A-Z])([A-Z])/', "$1_$2", $temp[ 2 ] ) );
$table_name = Zend_Registry::get( 'prefix' ) . strtolower( $temp[ 0 ] ) . '_' . $table_postfix . 's';
$db_table = new Zend_Db_Table( array( 'name' => $table_name ) );
$db_table->setRowClass( $row_class );
return $db_table;
} else {
return new $db_table_class();
}
}
}
The core of idea is to make my Factory look if requested class_name is defined and if it is not get Core_Model_Item as rowClass of instantiated Zend_Db_Table class. Surely Core_Model_Item extends Zend_Db_Table_Row class.
The line $db_table->setRowClass( $row_class );
doesn't take effect! I've tried to check if rowClass succesfully defined simply putting var_dump( $db_table->getRowClass() );
right after definition and it shows ""
— nothing is set! And lately this brings me the next error:
Warning: include_once(.php) [function.include-once]: failed to open stream: ��� ������ ����� ��� �������� in /home/users2/n/newpanel/domains/newpanel.jino/library/Zend/Loader.php on line 146
Warning: include_once() [function.include]: Failed opening '.php' for inclusion (include_path='/home/users2/n/newpanel/domains/newpanel.jino/application/../library:/home/users2/n/newpanel/domains/newpanel.jino/library:.:/usr/local/zend/share/pear') in /home/users2/n/newpanel/domains/newpanel.jino/library/Zend/Loader.php on line 146
Fatal error: Uncaught exception 'Zend_Exception' with message 'File ".php" does not exist or class "" was not found in the file' in /home/users2/n/newpanel/domains/newpanel.jino/library/Zend/Loader.php:99 Stack trace: #0 /home/users2/n/newpanel/domains/newpanel.jino/library/Zend/Db/Table/Abstract.php(1357): Zend_Loader::loadClass('') #1 /home/users2/n/newpanel/domains/newpanel.jino/library/Go/Factory.php(30): Zend_Db_Table_Abstract->fetchAll(Object(Zend_Db_Table_Select)) #2 /home/users2/n/newpanel/domains/newpanel.jino/application/modules/core/plugins/Acl.php(22): Go_Factory::reference('User_Model_Role') #3 /home/users2/n/newpanel/domains/newpanel.jino/application/Bootstrap.php(28): Core_Plugin_Acl::getAcl() #4 /home/users2/n/newpanel/domains/newpanel.jino/library/Zend/Application/Bootstrap/BootstrapAbstract.php(667): Bootstrap->_initNavigation() #5 /home/users2/n/newpanel/domains/newpanel.jino/library/Zend/Application/Bootstrap/BootstrapAbstract.php(620): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('na in /home/users2/n/newpanel/domains/newpanel.jino/library/Zend/Loader.php on line 99
Please help me figure out if I do something wrong.
The fatal error being thrown is due to the empty class being sent to the Zend_Loader. It looks like $db_table_class
is resulting in an empty string, which would mean the $class_name
argument is resulting as empty too. Check where you're calling Go_Factory::get();
and make sure your string there is not empty.
Also, you should change this:
if( !( class_exists( $db_table_class ) ) ){
to this:
if (!class_exists($db_table_class)) {
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.