In a continuation on my last post about Zend_Navigation, Route requests for sitemap.xml to custom controller/action, this post is about dymnamically adding pages to a Zend_Navigation container at runtime/script execution.
Its all well and good specifying your pages in a ini or xml file but at some point you’re going to have changing pages in your site that you want as part of a menu, sitemap, or to be included in your breadcrumb trail. Therefore what we need to do is add pages to our Zend_Navigation container at runtime. Examples for this would be in adding news items, blog posts, or page comments, etc.
Continue reading 'Dynamically add pages to Zend_Navigation container at runtime'»
PHP, Web Programming, Zend Framework
|
add, bootstrap, container, dynamically, Navigation, pages, PHP, sub-page, view, zend, Zend Framework, Zend_Navigation
In order to direct requests for /sitemap.xml to a custom controller and action in your Zend Framework application simply add the following in your application.ini or alternative config file (e.g. I use navigation.ini):
resources.router.routes.sitemap.route = "sitemap.xml"
resources.router.routes.sitemap.defaults.controller = index
resources.router.routes.sitemap.defaults.action = sitemap
Example code for outputting can be seen by creating an action in the appropriate controller (e.g. my sitemap lies in the index controller, sitemap action):
<php
class IndexController
extends Zend_Controller_Action
{
/**
* Renders a sitemap based on Zend_Navigation setup
*/
public function sitemapAction()
{
echo $this->view->navigation()->sitemap();
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
}
}
Sitemaps can quickly and easily be generated using Zend_Navigation, a great quick tutorial (and generally very useful for Zend Framework tutorials) is Zend Casts – Dynamically creating a menu a sitemap and breadcrumbs.
Articles, PHP, Web Programming, Zend Framework
|
framework, ini, PHP, Router, Routes, zend, Zend Framework, Zend_Navigation, Zend_Router