How to adding an automatically-generated sitemap.xml to a Zend Framework site?
It's really simple.
Now i will show you how to dynamically create a Google sitemap.xml file for your Zend Framework site. It assumes that you are using Zend_Navigation to describe the basic layout of your site. It also assumes that the application is based on Zend_Application and uses Zend_Layout.
First, we need to create the controller class used to field the request for the sitemap. This is called SitemapController and is located in controllers/SitemapController.php. The class has the following skeleton:
class SitemapController extends Zend_Controller_Action
{
// TODO: Implement the class action handlers here
}
The first action is the index action, which is handled by the follow method of the class: </>
public function indexAction()
{
$this->_helper->layout->disableLayout();
}
This disable the standard layout, so that only the XML of the sitemap is rendered.
The accompanying view script file is application/views/scripts/sitemap/index.phtml and contains the following code:
<?php $this->navigation()->sitemap()->setFormatOutput(true); echo $this->navigation()->sitemap();
That's all.
Date: 2012-01-16 08:14:38 and last modified: 2012-01-16 08:15:16
Recent entries:
- Emacs rainbow mode
- Squirm a url rewriter for squid
- How to use rsync for transferring files over ssh
- Vide: GRE tunnel
- Video: how to install freebsd
- Video: Install zend framework
- Video: Install Window7 from network
- Install Window7 from a PXE Boot server (Linux/FreeBSD)
- Create GRE tunnel with FreeBSD8
- What's cooking for FreeBSD 9