开发者

How do we iterate over the object that implements iterator

Iam rendering a menu (using Zend framework) (zend_navigation)

what iam doing is getting the page as label if the page has the value "myPage" than then iam setting the new URI with the page as expected

$it = new RecursiveIteratorIterator(
$container, RecursiveIteratorIterator::SELF_FIRST);

 foreach ($i开发者_JAVA技巧t as &$page) {
   $label = $page->label;
   if($label = "MyPage"){
    $newuri = "mypage.php?stcode=".$stcode."&cde=".$cde;            
    $page->setUri($newuri);
}           

}

In the above statement iam getting an error "An iterator cannot be used with foreach by reference". I want to use reference so that based on the label i can point the page to new uri

Now my problem and all the menu items in the menu are getting the same URI .


Does it work without the & ? Objects are passed by reference by default in PHP, so calling setUri should (in theory) modify the original object. Also note that your if statement is doing an assignment ($label = "MyPage") rather than a comparison ($label == "MyPage").

Assuming $container is your Zend Navigation object, the component has methods to make this easier anyway, so you should be able to simplify your code to:

$page = $container->findByLabel('MyPage');
$page->setUri("mypage.php?stcode=".$stcode."&cde=".$cde);

See http://framework.zend.com/manual/en/zend.navigation.containers.html#zend.navigation.containers.finding for some more examples.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜