2012-04-16 7 views
1

이 URL을 사용하여 Yii의 URL에 액세스하고 싶습니다. www.example.com/detail/post.Yii의 URL 다시 쓰기

나는이 URL을 처리 할 수 ​​있어야하거나 매개 변수 값 post가 있거나 어떤 행동에 명명 된 매개 변수 detail하고 값 post을 갖는 행동 detail합니다.

createUrl에 대한 Yii 문서를 읽었지만 이해할 수 없었습니다.

답변

2

나는 이것이 당신이 찾고있는 무슨 생각입니다 : (컨트롤러의 이름이 무엇 이건 컨트롤러/세부 사항을 말하는 부분의 변화 컨트롤러) 다음

업데이트 main.php

'urlManager' => array(
    'urlFormat' => 'path', 
    'showScriptName' => false, 
    'rules' => array(
      'detail/<post:\d+>'=>'controller/detail', 
      '<controller:\w+>/<id:\d+>' => '<controller>/view', 
      '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', 
      '<controller:\w+>/<action:\w+>' => '<controller>/<action>', 
    ), 
), 

기본적으로 Yii에게 detail/number 형식의 요청은 컨트롤러로 이동하여 "세부 사항"작업을 사용하고 "post"라는 변수를 전달합니다.

+0

답장을 보내 주셔서 감사합니다. – Arif

0

당신 모드 재 작성이 가능하고, 당신의 htaccess로 파일

php_value upload_max_filesize 1M 
DirectoryIndex index.php 

Options +FollowSymlinks 
RewriteEngine on 

# if a directory or a file exists, use it directly 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

# otherwise forward it to index.php 
RewriteRule . index.php 

에 다음을 배치하고 설정/main.php 파일에하여 'urlManager'배열에 다음을 추가하려는 경우 :

'showScriptName'=>false, 

url에서 index.php를 제거하고 domain.com/controller/action 형식으로 URL을 표시하십시오.