views:

30

answers:

1

I am trying to use the Zend Framework and I am having trouble figuring out how to pass information from the controller to the view.

It looks like I should be creating an instance of Zend_View, but when I call the render function I can't seem to get it to load the correct view file (for example, in indexAction, I can't get it to load the index.phtml file, no matter how hard I try).

Can someone tell me the best way to pass a variable from a controller to a view in the Zend Framework.

Thanks

Josh Pennington

+3  A: 

In your controller:

$this->view->myvar = $value

In your subsequent view file:

<?php echo $this->myvar ?>

However it sounds like maybe youre having trouble getting the proper view itself to load? Typically this is auto configured by the Controller Action based on naming convention. If you need to use an alternate template you can do:

$this->render('viewname.phtml')

Perhaps you could ellaborate a little more and tell us what errors you get, and post some code of what you are doing in your controller and view that isnt working.

prodigitalson
Just doing the $this->myvar worked great! A lot of the things I was finding around the net was telling me that I had to use a separate Zend_View object to pass information. Thanks for the help!
Josh Pennington