문제

What is the correct way to hide the /index action while having url parameters using Routing in CakePHP apps and the Html-Helper?

I want to be able to show urls like /books/2 while using the HTML helper

echo $this->Html->link('Books', array(
    'controller'=>'books', 'action'=>'index', 2
));

Tried the following in my routes.php

Router::connect('/books/:id', array('controller' => 'books'), array(
    'id' => '[0-9]+',
    'pass' => array('id')
));

Output is: http://www.example.com/books/index/2

Wanted is: http://www.example.com/books/2

도움이 되었습니까?

해결책

You'll need to use the id key in the routing array when creating links:

echo $this->Html->link('Books', array(
    'controller'=>'books', 'action'=>'index', 'id' => 2
));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top