0

3 つのカスタム ページ (コントローラー、php、および tpl ファイル) を作成し、SEO と URL のエントリを作成しました。現時点では、すべてのカスタム ページが重複しており、同じコンテンツが表示されます。

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;

リンクは機能しており、サイトは正しく表示されています。

私の問題は、わかりやすい URL が 1 ページしか表示されず、何が問題なのかまったくわからないことです。

正しく機能している URL は次のように変換されます。

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

私の他の 2 つのページは翻訳されていません。

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

問題が何であるかを知っている人はいますか?

4

1 に答える 1

0

関数 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;
}

.php@romainbergerが示唆するように、を削除します。しかし、あなたの状況ではそうではありません。次に、Dispatcher クラスの createUrl に飛び込みます。ここにすべてを貼り付けるつもりはありません。自分で掘り下げることもできますが、

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;
    }

これは、現在の言語のルートが正しく構成されていないことを意味します。

于 2013-01-16T22:37:15.227 に答える