I used to make my own layout for managing loading pages inside the index page
<div id="content">
<ul>
<li><a href="<?php echo $this->url(array('module' => 'visits', 'controller' => 'visit', 'action' => 'index', 'page' => 'view'), NULL, TRUE); ?>" class="showVisists">Display all visits</a></li>
<li><a href="<?php echo $this->url(array('module' => 'visits', 'controller' => 'visit', 'action' => 'index', 'page' => 'add'), NULL, TRUE); ?>" class="addVisit">Add new visit</a></li>
</ul>
<span class="result"><?php echo $this->message ?></span>
<div id="innerpage">
<?php include_once($this->pageToInclude . ".phtml") ?>
</div>
</div>
When I choose an anchor from the navigation, the parameter is received through the controller index action, which chooses the page I have to include and returns it to the index page so the page can be viewed.
public function indexAction() {
$status = $this->getRequest()->getParam('page');
switch ($status) {
case 'view':
$pageToInclude = 'get-visits';
break;
case 'add':
$pageToInclude = 'add';
break;
default:
$pageToInclude = 'get-visits';
}
$this->view->pageToInclude = $pageToInclude;
}
Now I want to use the layouts that are supported by Zend framework.
I enabled the layout and copied all the stuff in index to layout.phtml.
When I included pages inside the layout an error occurred. I know that I shouldn’t use includes or even require in Zend framework, but I don’t know how to show the view of “get all visits” when I click on the anchor “Display all visits” inside the layout page.
I want to make something like this:
<div id="innerpage">
<?php echo $this->layout()->content; ?>
</div>
but how should I specify the content dynamically?
Note: I am new to Zend framework, and not yet familiar on how to work with it effectively.
Hum your question is not 100% Clear. Is it AJAX based?
NON Ajax Based:
Just link from the Navigation to your Controller Action, than the corresponding “.phtml” View is redered in “content area”:
Best way to build your links inside the navigation ist the “url” Helper:
If you want to load the content with an ajaxRequest (i think you want to do this) just open the same controller action like in the sample above but disable the layout for this action:
by the way, if you want to use Actionnames with “-” you have to name the Actions like this in CamelCase: