rendered content of your view script. So assining a value to it in your
controller it is not working, because this value is replaced later on by
your view script content.
Try to use other "name" or "variable" to "placeholding" that value. Also you
can use the named segments to add different contents to your body. Each
named segment will have its equivalent placeholder in the layout. ZF layout
does this automagically for you.
On 17/08/2008 08:04, "edub" <ewahlstr@gmail.com> wrote:
>
> Hello - I am developing an application using ZF and I have run into a
> seemingly small problem to which I cannot find a good explanation or
> solution. I am using Zend_Layout for templating but I am confused on how
> exactly content is getting through to some of the code in the view scripts.
>
> I am working on a larger application but finally created a concept_test
> application to test basic principles of my code to see if I am using the
> framework correctly:
>
> My bootloader:
>
> <?php
> error_reporting(E_ALL|E_STRICT);
> ini_set('display_errors', 1);
>
> require_once 'Zend/Loader.php';
> Zend_Loader::registerAutoload();
>
> $options = array(
> 'layoutPath' => '/srv/www/concept_test/layouts',
> 'layout' => 'main_layout'
> );
> $layout = Zend_Layout::startMVC($options);
>
> $controller = Zend_Controller_Front::getInstance();
> $controller->setBaseUrl('/concept_test')
> ->addModuleDirectory('/srv/www/concept_test/modules/');
> $controller->dispatch();
>
> _____________________________________________________________________________-
> My main_layout.phtml:
>
> <html>
> <head>
> <title>Concept_Tester</title>
> </head>
> <body>
> <div>
> <div>Main Template Header</div>
> <div><?php echo $this->layout()->menu; ?></div>
> </div>
> <div>Before content: </div>
> <div><?php echo $this->layout()->content; ?></div>
> <div>After content</div>
> <div>
> <div>Main Template Footer</div>
> <div><?php echo $this->layout()->footerMenu; ?></div>
> </div>
> </body>
> </html>
>
> ___________________________________________________________________________
> My default module IndexController
>
> <?php
>
> class IndexController extends Zend_Controller_Action
> {
> public function indexAction()
> {
> //echo "index/index/default<br>";
> $this->view->layout()->menu = "Menu Text";
> $this->view->layout()->content = "Content Text<br>";
> //$this->_helper->actionStack('index','index','gui');
> }
> }
>
> ___________________________________________________________________________
> My default/views/scripts/index/index.phtml:
>
> <div>Body content from index/index.phtml</div>
>
>
______________________________________________________________________________>
_
> When I navigate to the index action, the (source) result in the browser is:
>
> <html>
> <head>
> <title>Concept_Tester</title>
> </head>
> <body>
> <div>
> <div>Main Template Header</div>
> <div>Menu Text</div>
>
> </div>
> <div>Before content: </div>
> <div><div>Body content from index/index.phtml</div></div>
> <div>After content</div>
> <div>
> <div>Main Template Footer</div>
> <div></div>
>
> </div>
> </body>
> </html>
>
> _____________________________________________________________________________
>
> Can someone please help with an explanation as to why the
> $this->view->layout()->menu = "Menu Text"; works as expected but the
> $this->view->layout()->content = "Content Text<br>"; does not?
>
> Thank you so much!
没有评论:
发表评论