Issues

ZF-11448: Problem with sitemap generation

Issue Type: Bug Created: 2011-06-07T11:24:10.000+0000 Last Updated: 2011-06-08T10:24:24.000+0000 Status: Closed Fix version(s): Reporter: Andrey (whyte624) Assignee: Kai Uwe (kaiuwe) Tags: - Zend_Navigation

  • Zend_View
  • View_Helper

Related issues: Attachments:

Description

I'm trying to create sitemap within controller. Controller code is:

<pre class="highlight">
<?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:


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:

<pre class="highlight">
$urlHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Url');

Zend_Debug::dump($urlHelper->url(
    array(
        'module' => 'default',
    ),
    null,
    true
));
Zend_Debug::dump($urlHelper->url(
    array(
        'module' => 'admin',
    ),
    null,
    true
));



<pre class="highlight">
string(39) "/test/public/sitemap.xml"

string(39) "/test/public/sitemap.xml"

The correct configuration:

<pre class="highlight">
$urlHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Url');

Zend_Debug::dump($urlHelper->url(
    array(),
    'default', // Route name
    true
));
Zend_Debug::dump($urlHelper->url(
    array(),
    'admin', // Route name
    true
));



<pre class="highlight">
string(28) "/test/public/"

string(33) "/test/public/admin"

Your xml-file should look like this:

<pre class="highlight">
<?xml version="1.0" encoding="UTF-8"?>
default
            defaultdefaultadmin
            adminadminadmin


<pre class="highlight">
<?xml version="1.0" encoding="UTF-8"?>
www.sitemaps.org/schemas/sitemap/0.9">
    <a href="http://localhost/test/public/">http://localhost/test/public/</a><a href="http://localhost/test/public/admin">http://localhost/test/public/admin</a>

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.

  • If the request is "sitemap.xml" and no route is given, then the current active route is used. In this case your custom route "sitemap".
  • If the request is "sitemap/xml" and no route is given, then the actual route instance with the name 'default' is used.

{quote} Maybe sitemap helper have to use urlHelper::simple($action) method. {quote} Very bad idea, because:

<pre class="highlight">
/**
 * Create URL based on default route
 * …
 */
public function simple($action, $controller = null, $module = null, array $params = null)

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.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts