发布于 2014-01-22 21:59:19
我已经知道了,我发现getParent(<itemType>)和getChildren(<itemType>)返回Core_Model_Item_Abstract。但是必须在子表模型和父表模型中分别设置$_parent_type和$_children_types[array] (而不是在_model_dbtable中)。
您还必须在子表getChildrenSelectOfItemType($obj,$params = array()中创建一个model(_Model_DbTable_),该表返回一个Zend_Db_Select,并且必须定义此选择将返回的内容。
在SE中,ItemType的意思是moduleName_itemname (例如,album_photo )。
假设帐户和bug具有1:n关系,因此下面的内容必须在MyModule_Model_DbTable_Bugs中。
public function getChildrenSelectOfMyModuleAccount($obj,$params = array())
{
$select = $this->select();
$select ->where('account_id = ?', $obj->getIdentity());
return $select;
}
}然后,您可以通过(在控制器中) $account=Engine_Api::_()->getItem('mymodule_account', 1); //1 = matching account_id获取相关的子级。
$bug=$account->getChildren('mymodule_bug'); //return Core_Model_Item_Abstract or row obj。
获取父表行并不那么复杂,在子表中声明$_parent_type和parent_id列必须出现在数据库子表中-bug中。
$bug=Engine_Api::_()->getItem('mymodule_bug', 1); //1 = bug_id $account=$bug->getParent();** //return Core_Model_Item_Abstract/row obj (不要忘记在带有匹配id的db bug表中放置一个引用列(parent_id) )
如果在MyModule_Model_Bug中设置“$_owner_type”(而不声明$_owner_type和$_parent_type),则用户将成为父级,因此getParent将返回用户
最重要的一件事是
主体、查看者和所有者
在社会恩格斯的背景下。
查看器=任何正在查看页面的人(主要是登录用户).e.g。John是一个登录用户,他正在查看照片-a主题。
subject = Subject由查看器查看,并且/或查看器实际查看主题。如果用户John查看相册/照片,相册/照片就是主题。
Owner=Owner拥有一个项/主题。(.If)约翰正在看曾傑瑞的照片,主题是曾傑瑞的照片,但主人是曾傑瑞。
发布于 2014-01-21 06:34:46
( 1)是的,它们用于父子关系,但不是通过Zend原生机制(_dependentTables、_referenceMap等)。
您可以在这里找到以下方法:抽象类Core_Model_Item_Abstract扩展Engine_Db_Table_Row实现Core_Model_Item_Interface Core_Model_Item_Interface
寻找方法参数,它们很重要。
2)通常用于检索数据库行/行。例如,查看Group_PhotoController::editAction():
//按id获取照片(engine4_group_photos.photo_id)
$photo = Engine_Api::_()->core()->getSubject();//通过group_id (engine4_group_photos.group.id)查找父母
$group = $photo->getParent('group');我们在这里得到组行对象(Group_Model_Group)。
当然,您可以重写这些方法。参见这里的例子:类Album_Model_Photo扩展Core_Model_Item_Abstract::getParent($type = null)
3)您可能会尝试,但这可能很棘手,因为SE从Zend框架代码库中更改了很多。
https://stackoverflow.com/questions/21195286
复制相似问题