Author Topic: Dynamic Sidebar Content w/ Zend Framework  (Read 3682 times)

0 Members and 1 Guest are viewing this topic.

Offline shlumphTopic starter

  • Enthusiast
  • Posts: 451
  • Gender: Male
    • View Profile
    • My Site
Dynamic Sidebar Content w/ Zend Framework
« on: June 15, 2008, 11:19:36 AM »
Hi,

I'm a complete newb trying to learn the zend framework. I set up a 'master page' with zend_layout, and the "content" section is working fine with my controllers/views. However, I want my sidebar to be dynamic as well, and I can't figure out how. My directory structure looks like this:

+application
   +default
      +controllers

         -IndexController.php
      +layouts
         -layout.phtml
      +models
      +views
         +scripts
            +index

            -sidebar.phtml

My simplified layout.phtml file looks like this:
Code: [Select]
<html>
<body>
<div id="content">
     <?php echo $this->layout()->content?>
</div>
<div id="navigation">
</div>
     <?php echo $this->layout()->sidebar?>
</body>
</html>


This is an example of one of my controllers:
Code: [Select]
<?php
class IndexController extends Zend_Controller_Action 
{

public function init(){
$response $this->getResponse();
                
$response->insert('sidebar'$this->view->render('sidebar.phtml'));
}

        
//other functions below


My sidebar.phtml file looks something like this:
Code: [Select]
<div class="navigation">
<h1>Recent Posts</h1>
<ul>
<?php echo $this->iWantToBeDynamic?>
</ul>
</div>
<div class="navigation">
<h1>Categories</h1>
<ul>
<?php echo $this->iWantToBeDynamic?>
</ul>
</div>

Is it possible to add a controller to my sidebar.phtml file? If so, how, if not, what is the best possible way to make this sidebar dynamic?
« Last Edit: June 15, 2008, 11:23:23 AM by shlumph »
whether you think you can, or can't, you're right -HF
Visit my website or github

Offline shlumphTopic starter

  • Enthusiast
  • Posts: 451
  • Gender: Male
    • View Profile
    • My Site
Re: Dynamic Sidebar Content w/ Zend Framework
« Reply #1 on: June 15, 2008, 01:26:58 PM »
Ok, I made a "classes" folder in my application directory, and made a "Sidebar" class, that accesses a model.

Then I created an instance of that Sidebar class in my sidebar.phtml view.

That's the best I could come up with, seems to work fine. Zend is overwhelming me.
whether you think you can, or can't, you're right -HF
Visit my website or github