My problem getting Zend Framework to provide a DRI layer can now be summarized as such.
我现在可以总结出让Zend Framework提供DRI层的问题。
Using the class definitions below I am able to delete the user but not the related comment through my local UserController "public/users/delete/userId/22", even though I have set up a refernece map and table relationship definition.
使用下面的类定义,我能够通过我的本地UserController“public / users / delete / userId / 22”删除用户但不能删除相关注释,即使我已经设置了一个refernece map和table relationship definition。
Does anyone have any answers to why the associated comment record is not deleted when i delete the users record?
当我删除用户记录时,有没有人对为什么没有删除相关评论记录有任何答案?
class Default_Model_DbTable_Comment extends Zend_Db_Table_Abstract
{
/**
* @var string Name of the database table
*/
protected $_name = 'comment';
/**
* @desc reference map
*
* Rows in the comment table are to be automatically deleted if the row in the
* User table to which they refer is deleted
*
*/
protected $_referenceMap = array(
'User' => array(
'columns' => 'user_id', // the foreign key(s)
'refTableClass' => 'Default_Model_DbTable_Users',
'refColumns' => 'id',
'onDelete' => self::CASCADE,
)
);
}
class Default_Model_DbTable_Users extends Zend_Db_Table_Abstract
{
/**
* @var string Name of the database table
*/
protected $_name = 'users';
/**
* @desc Defining referential integrity here since we are using MyISAM
* Dependent tables are referred via the class name.
*/
protected $_dependentTables = 'Default_Model_DbTable_Comment';
}
1 个解决方案
#1
I've created models as yours and on testing it appears that it only works if dependent tables are listed in an array:
我已经创建了你的模型,并且测试它似乎只有在数组中列出依赖表时它才有效:
class Default_Model_DbTable_Users extends Zend_Db_Table_Abstract
{
/**
* @var string Name of the database table
*/
protected $_name = 'users';
/**
* @desc Defining referential integrity here since we are using MyISAM
* Dependent tables are referred via the class name.
*/
protected $_dependentTables = array('Default_Model_DbTable_Comment');
}
When they aren't listed in an array, I get the error
当它们没有列在数组中时,我收到错误
Warning: Invalid argument supplied for foreach() in C:\PHP\includes\ZendFramework-1.8.4-minimal\library\Zend\Db\Table\Row\Abstract.php on line 632
警告:在第632行的C:\ PHP \ includes \ ZendFramework-1.8.4-minimal \ library \ Zend \ Db \ Table \ Row \ Abstract.php中为foreach()提供的参数无效
This error may not have been visible in your environment.
您的环境中可能未显示此错误。
#1
I've created models as yours and on testing it appears that it only works if dependent tables are listed in an array:
我已经创建了你的模型,并且测试它似乎只有在数组中列出依赖表时它才有效:
class Default_Model_DbTable_Users extends Zend_Db_Table_Abstract
{
/**
* @var string Name of the database table
*/
protected $_name = 'users';
/**
* @desc Defining referential integrity here since we are using MyISAM
* Dependent tables are referred via the class name.
*/
protected $_dependentTables = array('Default_Model_DbTable_Comment');
}
When they aren't listed in an array, I get the error
当它们没有列在数组中时,我收到错误
Warning: Invalid argument supplied for foreach() in C:\PHP\includes\ZendFramework-1.8.4-minimal\library\Zend\Db\Table\Row\Abstract.php on line 632
警告:在第632行的C:\ PHP \ includes \ ZendFramework-1.8.4-minimal \ library \ Zend \ Db \ Table \ Row \ Abstract.php中为foreach()提供的参数无效
This error may not have been visible in your environment.
您的环境中可能未显示此错误。