URL에 ID가없는 케이크에 URL을 라우팅 할 수있는 방법이 있습니까?id가없는 cakephp 라우팅?
그래서 대신 www.mydomain.com/id/article-name 난 그냥이 다음 봤는데
www.mydomain.com/article-name합니다. http://book.cakephp.org/view/543/Passing-parameters-to-action
URL에 ID가없는 케이크에 URL을 라우팅 할 수있는 방법이 있습니까?id가없는 cakephp 라우팅?
그래서 대신 www.mydomain.com/id/article-name 난 그냥이 다음 봤는데
www.mydomain.com/article-name합니다. http://book.cakephp.org/view/543/Passing-parameters-to-action
확실히. 이것에 대한 유일한 요구 사항은 URL에 고유 한 정보가있어 원하는 기사를 고정시킬 수 있어야한다는 것입니다. /article-name
이 데이터베이스에서 고유 한 경우이를 사용하여 원하는 특정 레코드를 찾을 수 있습니다. 설정/routes.php에서
: 컨트롤러에서
// ... configure all normal routes first ...
Router::connect('/*', array('controller' => 'articles', 'action' => 'view'));
/articles_controller.php :
function view ($article_name) {
$article = $this->Article->find('first', array(
'conditions' => array('Article.name' => $article_name)
));
...
}
하기 때문에, 합법적으로 URL에 게재 될 수 있습니다 아무것도 같은 제품을 이름을하지 않도록주의 당신은 갈등을 겪지 않습니다. http://example.com/pages
URL이 제품 '페이지'또는 array('controller' => 'pages', 'action' => 'index')
을 가리 킵니까? 이 목적을 위해 routes.php
에 경로를 정의해야합니다. 그러면 모든 컨트롤러를 먼저 액세스 할 수 있고 정의되지 않은 나머지는 ArticlesController
에 파이프됩니다. third parameter of Routes::connect
을 보면이 용도로 사용할 수있는 RegEx 필터를 지정할 수 있습니다.
이 작업을 수행 할 수 있습니다 : deceze의 방법으로
// In routes.php
$rewrites = array();
$rewrites = am($rewrites, ClassRegistry::init('Article')->rewrites());
$rewrites = am($rewrites, ClassRegistry::init('AnotherModel')->rewrites());
$rewrites = am($rewrites, ClassRegistry::init('YetAnother')->rewrites());
foreach ($rewrites as $rewrite) {
Router::connect($rewrite[0], $rewrite[1], $rewrite[2]);
}
, 당신은 모두 하나의 캐치를 가질 수 있습니다. 이 방법에서는 원하는 경우 전체 스택을 정의 할 수 있습니다.
이 방법은 구성 파일에서 모델을 쿼리하기 때문에 일종의 해킹입니다.