ZF-11448: Problem with sitemap generation
Description
I'm trying to create sitemap within controller. Controller code is:
<?php
class SitemapController extends Zend_Controller_Action
{
function xmlAction()
{
$this->_helper->viewRenderer->setNoRender();
$this->_helper->getHelper('layout')->disableLayout();
$this->getResponse()->setHeader('Content-Type', 'text/xml; charset=utf-8');
echo $this->view->navigation()->sitemap();
}
}
I want to view the same sitemap in http://localhost/sitemap.xml and http://localhost/sitemap/xml. For this I'm creating route in bootstrap:
protected function _initFrontController() {
$front = Zend_Controller_Front::getInstance();
$front->setControllerDirectory(
array(
'default'=>APPLICATION_PATH.'/modules/default/controllers',
'admin'=>APPLICATION_PATH.'/modules/admin/controllers',
)
);
$router = $front->getRouter();
$router->addRoute(
'sitemap',
new Zend_Controller_Router_Route('sitemap.xml', array('controller'=>'sitemap','action'=>'xml','module'=>'default'))
);
$front->setRouter($router);
$front->registerPlugin(new Zend_Controller_Plugin_ErrorHandler());
return $front;
}
But result is different.
For /sitemap/xml I see:
http://127.0.0.1/http://127.0.0.1/admin
And in sitemap.xml I see:
http://127.0.0.1/sitemap.xmlhttp://127.0.0.1/sitemap.xml
This is my navigation (xml) file:
<?xml version="1.0" encoding="UTF-8"?>
defaultdefaultdefaultadminadminadminadmin
_request objects in SitemapController are the same. I think this is bug.
Comments
Posted by Kai Uwe (kaiuwe) on 2011-06-08T06:55:54.000+0000
Code tags added.
Posted by Kai Uwe (kaiuwe) on 2011-06-08T07:36:48.000+0000
This not a bug! This is the normal behavior from Zend_Controller_Action_Helper "url".
Your configuration:
The correct configuration:
Your xml-file should look like this:
Posted by Andrey (whyte624) on 2011-06-08T09:12:17.000+0000
I don't think that this explains everything. Your configuration needs routes had been created, and this is not mondatory in navigation.xml. But if sitemap/xml works fine, then why sitemap.xml (routing to sitemap/xml) generates wrong urls?
Posted by Kai Uwe (kaiuwe) on 2011-06-08T09:26:59.000+0000
Hi Andrey, please have a look at ZF-11261 and my comment on it.
Posted by Andrey (whyte624) on 2011-06-08T09:32:06.000+0000
Thank you, Kai. But my problem not with route indeed. I think, that if I'm trying to create sitemap from the same container, I have to see equal results. Maybe sitemap helper have to use urlHelper::simple($action) method. I don't know.
Posted by Kai Uwe (kaiuwe) on 2011-06-08T09:53:54.000+0000
{quote} I think, that if I'm trying to create sitemap from the same container, I have to see equal results. {quote} No problem: add the route names to your xml configuration. That's all.
{quote} Maybe sitemap helper have to use urlHelper::simple($action) method. {quote} Very bad idea, because:
The method "simple" never use your custom routes!
By the way, the creation of URLs is not the task of Zend_Navigation and their helpers. It is also not allowed to change the behavior of Zend_Controller_Router.
Greetings Kaiuwe
Posted by Kai Uwe (kaiuwe) on 2011-06-08T10:00:13.000+0000
{quote} It is also not allowed to change the behavior of Zend_Controller_Router. {quote} Better: Zend_Navigation is not allowed to change the behavior.
Posted by Andrey (whyte624) on 2011-06-08T10:05:11.000+0000
{quote} No problem: add the route names to your xml configuration. That's all. {quote} When I'm adding route "admin" I see only one url in sitemap: default.
I found that url is generating in Zend_Controller_Router_Rewrite::assemble And if I'm requesting sitemap/xml route object is instance of Zend_Controller_Router_Route_Module
but if I'm requesting sitemap.xml route object is instance of Zend_Controller_Router_Route_Static
Posted by Andrey (whyte624) on 2011-06-08T10:09:49.000+0000
I don't understand exactly why sitemap helper depends on route, but not on navigation container data.
Posted by Kai Uwe (kaiuwe) on 2011-06-08T10:15:44.000+0000
{quote} I don't understand exactly why sitemap helper depends on route, but not on navigation container data. {quote} The navigation container data is always used! Only for the creation of the URLs the route name is needed.
Posted by Kai Uwe (kaiuwe) on 2011-06-08T10:21:02.000+0000
Please add to all your routes in the configuration file the a route name.
Should there be other problems, then write me an email. The bug tracker is not a discussion forum!
Posted by Kai Uwe (kaiuwe) on 2011-06-08T10:24:24.000+0000
Sorry: add to all your pages in the configuration file the a route name.