2008年8月16日星期六

[fw-mvc] Zend View with Zend Layout Question

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!
--
View this message in context: http://www.nabble.com/Zend-View-with-Zend-Layout-Question-tp19017745p19017745.html
Sent from the Zend MVC mailing list archive at Nabble.com.

没有评论: