0

I've created 3 custom pages (controller-, php-, and tpl-files) and created entries for SEO & URLs. All custom pages are duplicates at the moment and show the same content.

I have created the links for the custom pages in blocktopmenu.php:

$this->_menu .= '<li><a href="'.$this->context->link->getPageLink('bHome.php').'">Home</a></li>'.PHP_EOL;
$this->_menu .= '<li><a href="'.$this->context->link->getPageLink('bSamples.php').'">Samples</a></li>'.PHP_EOL;
$this->_menu .= '<li><a href="'.$this->context->link->getPageLink('start.php').'">Test</a></li>'.PHP_EOL;

The links are working and the sites are displayed correctly.

My problem is, that only one pages friendly URL is shown and I don't have the slightest idea what the problem could be.

The URL that is working correctly is translated as follows:

http://localhost/Shop/index.php?controller=start -> http://localhost/Shop/Test

My other two pages are not translated:

http://localhost/Shop/index.php?controller=bHome
http://localhost/Shop/index.php?controller=bSamples

Does anybody know what the problem might be?

user1567896
  • 2,398
  • 2
  • 26
  • 43
  • I don't know if this has an effect but with Prestashop 1.5 you don't need to add the `.php` extension in the `getPageLink()` method. You can use `bSamples` or `start` only – romainberger Jan 15 '13 at 15:09
  • Thanks for your answer but unfortunately that does not work either. – user1567896 Jan 15 '13 at 15:44

1 Answers1

0

Well let's take a look to the function getPageLink:

public function getPageLink($controller, $ssl = false, $id_lang = null, $request = null, $request_url_encode = false)
{
    $controller = Tools::strReplaceFirst('.php', '', $controller);

    if (!$id_lang)
        $id_lang = (int)Context::getContext()->language->id;

    if (!is_array($request))
    {
        // @FIXME html_entity_decode has been added due to '&amp;' => '%3B' ...
        $request = html_entity_decode($request);
        if ($request_url_encode)
            $request = urlencode($request);
        parse_str($request, $request);
    }

    $uri_path = Dispatcher::getInstance()->createUrl($controller, $id_lang, $request);
    $url = ($ssl && $this->ssl_enable) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true);
    $url .= __PS_BASE_URI__.$this->getLangLink($id_lang).ltrim($uri_path, '/');

    return $url;
}

It removes the .php as @romainberger suggests. But that is not the case in your situation. Next we dive into createUrl in Dispatcher class. I'm not going to paste it all here, and you might as well dig in yourself but:

public function createUrl($route_id, $id_lang = null, array $params = array(), $force_routes = false, $anchor = '')
{
    if (!$id_lang)
        $id_lang = Context::getContext()->language->id;

    if (!isset($this->routes[$id_lang][$route_id]))
    {
        $query = http_build_query($params, '', '&');
        $index_link = $this->use_routes ? '' : 'index.php';
        return ($route_id == 'index') ? $index_link.(($query) ? '?'.$query : '') : 'index.php?controller='.$route_id.(($query) ? '&'.$query : '').$anchor;
    }

I'm pretty sure this is the case here, meaning that the routes in the current language are not correctly configured.

povilasp
  • 2,386
  • 1
  • 22
  • 36