SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [ZF] renders twice the view script....?

    Hi,

    I'm playing with the ZF. When I render a view, it gets rendered twice....

    Here is my controller script:

    PHP Code:
    <?php

    class TestController extends Zend_Controller_Action
    {


      function 
    testViewAction()
      {
      
        
    $view = new Zend_View();
        
    $view->assign('a'"Hay");
        
    $view->assign('b'"Bee");
        
    $view->assign('c'"Sea");
        
        
    $view->setScriptPath('application/views/scripts/test/');
        
        
    $render $view->render('test-view.phtml');
        
        echo(
    $render);
      
      }

    }
    Here is my view script:
    PHP Code:

    <ul>
    <li><?php echo($this->a); ?></li>
    <li><?php echo($this->b); ?></li>
    <li><?php echo($this->c); ?></li>
    </ul>
    Here is the outputed html. As you'll notice, the first rendering doesn't get what is between the php tags...

    Code:
    <ul>
    <li></li>
    <li></li>
    <li></li>
    </ul>
    <ul>
    <li>Hay</li>
    <li>Bee</li>
    <li>Sea</li>
    </ul>
    I've chcked my index/bootstrap, Zend_View isn't instantiated somewhere else...

    I'm a bit lost

    Regards,

    -jj.

  2. #2
    SitePoint Zealot Amenthes's Avatar
    Join Date
    Oct 2006
    Location
    Bucharest, Romania
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ZF has a built-in Action helper called ViewRenderer, which is active by default. This helper is the one that outputs the empty list, as the template file is on a path conforming with the built-in app structure of ZF.

    You must either do this in bootstrap:

    PHP Code:
    Zend_Controller_Front:getInstance()->setParam('noViewRenderer'true); 
    ...either use the built-in helper. Like this:

    PHP Code:
    class TestController extends Zend_Controller_Action
    {
      function 
    testViewAction()
      {
        
    $this->view->"Hay";
        
    $this->view->"Bee";
        
    $this->view->"Sea";
      }

    The helper will take care of the template loading and output.

  3. #3
    Made with a Mac! philm's Avatar
    Join Date
    Sep 2001
    Location
    Portsmouth, UK
    Posts
    735
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ZEND takes care of rendering the view for you automatically, unless you're specifically trying something out of the ordinary?

    Your calling render manually a 2nd time which is why it's appearing twice...

    EDIT: Oops, too late Amenthes got there first

  4. #4
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot guys


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •