2010-03-19 3 views
2

다른 유형의 게시물이 다른 URL을 가지도록 내 경로를 설정하는 가장 좋은 방법은 무엇입니까? 기능을 갖춘 게시물 /featured/slug게시 유형에 따라 다른 URL로 라우팅

같은 컨트롤러와 액션 /posts/view/slug에 모두 링크를하는 동안

예를 들어, 일반 게시물은 /posts/slug 있습니다.

나는이 작업을 여러 가지 방법으로 시도했지만 거의 성공하지 못했습니다.

array('controller' => 'posts', 'action' => 'view', 'featured' ,$post['Post']['slug']) 

편집 : 현재 내 링크 PARAMS는 다음과 같이 보일 나는 각각 다른 유형에 대한 작업을 생성하고 대신에 뷰 액션을 사용하기에, setAction를 사용할 수 있습니다. 이것을하기위한 더 좋은 방법이 있긴하지만? 이것은 작동 할 수

Router::connect('/:controller/featured/*',array('action' => 'view')); 

route setting in cookbook

답변

3

난 당신이 또한 /app/config/routes.php에 후속 라인을 추가하여이 작업을 수행 할 수 있다고 생각

// app/config/routes.php 
Router::connect('/featured/:slug', array(
    'controller' => 'posts', 
    'action' => 'view', 
    'type' => 'featured' 
)); 
Router::connect('/posts/:slug', array(
    'controller' => 'posts', 
    'action' => 'view', 
    'type' => 'normal' 
)); 

// one of your views 
echo $html->link('Featured post title', array(
    'controller' => 'posts', 
    'action' => 'view', 
    'type' => 'featured', 
    'slug' => $post['Post']['slug'] 
)); 
or 
echo $html->link('Normal post title', array(
    'controller' => 'posts', 
    'action' => 'view', 
    'type' => 'normal', 
    'slug' => $post['Post']['slug'] 
)); 
0

를 참조하십시오 :

array('controller' => 'posts', 'action' => 'featured', $post['Post']['slug']) 

function featured($slug) { 
    $this->setAction('view', $slug); 
} 
관련 문제