zend_db_table setRowClass 不绑定我的自定义类而不是 Zend_Db_Table_Row
为了减少编写,我尝试扩展默认的 Zend ORM 系统。我的意思是,如果我们通过 Zend_Db_Table 从 Db 获取一些数据,我们稍后可以使用 Zend_Db_Table_Rowset 或 Zend_Db_Table_Row 类处理这些数据。 我的想法是使用这样的自定义 Factory 类:
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();
}
}
}
想法的核心是让我的 Factory 看看是否定义了请求的 class_name ,如果没有定义,则获取 Core_Model_Item 作为实例化 Zend_Db_Table 类的 rowClass 。当然,Core_Model_Item 扩展了 Zend_Db_Table_Row 类。
$db_table->setRowClass( $row_class );
行不生效!我尝试检查 rowClass 是否成功定义,只需在定义之后放置 var_dump( $db_table->getRowClass() );
,它会显示 ""
— 没有设置任何内容!最近这给我带来了下一个错误:
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
请帮助我弄清楚我是否做错了什么。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抛出的致命错误是由于空类被发送到 Zend_Loader 造成的。看起来
$db_table_class
生成了一个空字符串,这意味着$class_name
参数也生成为空。检查您在哪里调用Go_Factory::get();
并确保您的字符串不为空。另外,您应该将其更改
为:
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 callingGo_Factory::get();
and make sure your string there is not empty.Also, you should change this:
to this: