0

私は検索モジュールに取り組んでいます。アイテムを検索すると、そのアイテムのスラッグがクエリ文字列として URL に渡されますが、それを名前付きパラメーターに変換したいと考えています。このためurlToNamed()に、カスタム コンポーネント RedirectComponent.php でアクションを作成しました。私のコードは次のとおりです。

 RedirectComponent.php

 function urlToNamed() {
    $urlArray = $this->controller->params->query;
    if(!empty($urlArray)){
        #remove unset values
        $urlArray = array_filter($urlArray);
        $this->controller->redirect($urlArray);
    }
}     

 I am calling the urlToNamed() action from index action of BooksController.php i.e


 public function index() { 
    $this->Redirect->urlToNamed();

    //All other stuff to handle named parameter data and show result.
 }

問題は、検索後の私の URL です。データは、のようhttp://localhost/esolutions/books/index?category=Booksな名前付きパラメーターに変換する必要があるようなクエリ文字列http://localhost/esolutions/books/index/category:Booksです。

もう一つの問題は、

 $this->controller->redirect($urlArray);

動かない。何か提案をお願いします。前もって感謝します。

4

1 に答える 1

0

クエリ文字列パラメーターを名前付きパラメーターに変更する必要がある場合は、この機能をindex()アクションに追加します。

public function index($category = null) {
    if (isset($this->request->query['category'])) {
        $this->redirect(array('category' => $this->request->query['category']), 301);
    }

    // rest of index code as normal
}

これにより、 /esolutions/books/index/?category=fooなどの URL の 301 リダイレクトが/ esolutions/books/index/category:fooに実行されます。

于 2013-10-03T11:32:24.753 に答える