PHPEye开源社区 » Zend Framework 使用讨论 » 问一下插件怎么用?
《Programming PHP》第二版上市
2007-12-23 16:36 bc1998
问一下插件怎么用?

[url]http://framework.zend.com/wiki/display/ZFPROP/Zend_Db_Table_Rowset_Recursive_Abstract+Adrian+Hope-Bailie[/url]
这个,怎么用啊

2007-12-23 18:01 haohappy
这不是什么插件呀,这个东西的功能就是要让Rowset可以递归遍历而已。

2007-12-24 06:54 bc1998
[quote]原帖由 [i]haohappy[/i] 于 2007-12-23 18:01 发表 [url=http://www.phpeye.com/bbs/redirect.php?goto=findpost&pid=1069&ptid=293][img]http://www.phpeye.com/bbs/images/common/back.gif[/img][/url]
这不是什么插件呀,这个东西的功能就是要让Rowset可以递归遍历而已。 [/quote]
那怎么用呢?

2007-12-24 10:06 haohappy
你贴的这个只是一个Proposal(提案),还没有正式被ZF所采纳,还未实现,只是一个想法而已。

至于用法,网页中不是都有假想的示例代码吗?

先定义一个可以递归遍历的Rowset类:
class My_Db_Table_Rowset_Recursive extends Zend_Db_Table_Rowset_Recursive_Abstract
{
    protected $_childId = 'id';
    protected $_parentId = 'parent_id';
}

然后在Model中设定一下你使用的Rowset类为刚才定义的类:

class MyComments extends Zend_Db_Table_Abstract
{
    protected $_name = 'Comments';

    protected $_rowsetClass = 'My_Db_Table_Rowset_Recursive';

}

这样你就可以在View中根据需要设定遍历几层,(比如下面的例子中可以遍历三层):
<?php      
      $comments = new RecursiveIteratorIterator($this->comments);
      foreach($comments as $comment):  
      //We can use the getDepth() method to determine the depth of the recursive iteration
?>
<div style="margin-left: <?php echo ($comments->getDepth() * 3);?>px;">
<?php echo $comment->comment; ?>
</div>
<?php endforeach; ?>
}

页: [1]
查看完整版本: 问一下插件怎么用?


Powered by Discuz! Archiver 5.5.0  © 2001-2006 Comsenz Inc.