私は検索モジュールに取り組んでいます。アイテムを検索すると、そのアイテムのスラッグがクエリ文字列として 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);
動かない。何か提案をお願いします。前もって感謝します。