Best practice for creating a dynamic sidebar using zend framework

What is the best practice for creating dynamic sidebars or other placements without content using the zend frame. At this point, I created a controller, which I called WidgetsController. In this controller, I defined some actions with the โ€œsidebarโ€ response segment for my sidebar, and in IndexController I call them using $ this-> view-> action (); but I donโ€™t think itโ€™s best practice to create a dynamic sidebar. Thank you for your responses.

+5
source share
4 answers

Your question does not contain many details. Typically, I would say load the sidebar as a view template using the render / partial view methods. So, from within the view:

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

And then the sidebar can process this 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 additional functionality, you can create a special viewing assistant to handle it.

+8
source

, , , - . , CI , . ZF, , "named view" ZF "Partials".

ZF , โ€‹โ€‹ + + , , , , " ".

( , ZF , CI .)

$navigation- > setPartial (-), leadup ( "" MVC) .

, , , , , .

, Zend, , .

-2

, , (, <ul>, <div> - ), - , , .

CodeIgniter, Model, View, Controller, "sidebar.php" Header, , :

<html>
<head>.......</head>
<div id="header">....</div>
<?php $this->load->view('sidebar');?>

The sidebar window contains the logic for displaying menu items. This is usually a static menu, but if it was dynamic and had to be retrieved from the database, I would do the following:

<ul>
   <?php
   $items=$this->some_model->getMenuItems();
   foreach ($items as $item):
   ?>
     <li><a href="<?=$item['url'];?>"><?=$item['text'];?></li>
   <?php endforeach;?>
</ul>
-4
source

All Articles