Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice creating dynamic sidebar with zend framework

What is best practice to create dynamic sidebar or other non content layout places with zend framework. At this moment I created controller witch i called WidgetsController. In this controller i defined some actions with 'sidebar' response segment for my sidebar and in IndexController i call them with $this->view->action(); function but I don't think that is a best practice to create dynamic sidebar. Thanks for your answers.

like image 632
Irmantas Avatar asked Nov 05 '22 22:11

Irmantas


1 Answers

You question doesn't provide many details. Generally, I'd say load the sidebar as view template, via the render/partial methods of the view. So from inside a view:

//$data is dynamic data you want to pass to the sidebar
echo $this -> partial('/path/to/sidebar.phtml',array('menuitems' => $data));

And then sidebar could process that dynamic data:

//sidebar.phtml
<div id="sidebar">

    <?php foreach($this -> menuitems as $item) : ?>
    <a href="<?php echo $item['url']; ?>"><?php echo $item['title']; ?></a>
    <?php endforeach; ?>

</div>

If you need extra functionality, you could create a dedicated view helper to handle it.

like image 100
Eran Galperin Avatar answered Nov 11 '22 19:11

Eran Galperin