2012-09-03 2 views
0

여기 내 설정이다 :Yii 색인 제거 - 무엇이 누락 되었습니까?

config.php를

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

htaccess로 :

$this->widget('zii.widgets.CMenu', 
    array('items'=> 
     array(
      array(
       'label'=>Yii::t('site','A'), 
       'url'=>array('/site/index') 
      ), 
      array(
       'label'=>Yii::t('site','Q'), 
       'url'=>array('rooms/index') 
      ), 
      array(
       'label'=>Yii::t('site','G'), 
       'url'=>array('gastronomy/index') 
      ), 
      array(
       'label'=>Yii::t('site','A'), 
       'url'=>array('activity/index') 
      ), 
      array(
       'label'=>Yii::t('site','S'), 
       'url'=>array('services/index') 
      ), 
      array(
       'label'=>Yii::t('site','C'), 
       'url'=>array('contacts/index') 
      ), 
      array(
       'label'=>Yii::t('site','R'), 
       'url'=>array('booking/index') 
      ) 
     ) 
    ) 
); 
: 레이아웃 메뉴에

Options +FollowSymlinks 
#+FollowSymLinks must be enabled for any rules to work, this is a security 
#requirement of the rewrite engine. Normally it's enabled in the root and we 
#shouldn't have to add it, but it doesn't hurt to do so. 

RewriteEngine on 
#Apache scans all incoming URL requests, checks for matches in our 
#.htaccess file 
#and rewrites those matching URLs to whatever we specify. 

#allow blank referrers. 
RewriteCond %{HTTP_REFERER} !^$ 
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?site.com [NC] 
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?site.dev [NC] 
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?dev.site.com [NC] 
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L] 

# 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 

나는이 있습니다

명시 적으로 여기를 호출하는 것이므로 명시 적으로 호출해야합니다. 이 설정으로

, I 예를 들어, 내가 할 그 링크를 클릭 할 때마다 :

http://site.dev/rooms/

W/아웃 지수 :

http://site.dev/rooms/index

내가 얻을하고자하는 동안 이름.

무엇이 여기에 있습니까?

답변

3

색인 항목 파일과 기본 작업 간에는 차이가 있습니다. 너는 그 일을 망치고있어. 'showScriptName'=>true을 만들면 링크가 /index.php/rooms/index과 같이 변경됩니다. 여기서 index.php은 색인 항목 파일입니다.

'showScriptName'=>false 옵션에서 볼 수 있듯이 링크에 index.php이 없으므로 링크에서 입력 스크립트를 성공적으로 제거했음을 의미합니다. 은 입니다. room은 컨트롤러이고 index은 조치입니다. 는 그런 당신의 URL 경로를 편집해야 http://site.dev/rooms/ 대신 http://site.dev/rooms/index 보려면 :

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

공지 사항 내가 추가 한 라인 '<controller:\w+>'=>'<controller>/index'. 따라서 기본 동작 indexcontroller/index 대신에 controller 경로를 생성합니다.

+0

시간을내어 설명해 주셔서 감사합니다. 아니 행운 그러나. 새롭게 추가 된 라인이 정말로 필요합니까? Yii는 인덱스가 기본적으로 기본 컨트롤러를 가지고 있다고 정의하지 않습니까? - 내 말은, 그 라인을 추가했는데, 나는 여전히 URL과 같은 인덱스를 보았습니다. :( – MEM

+0

@MEM 내가 당신에게 보여준 것과 동일한 순서? 규칙은 순서에서 중요합니다. 컨트롤러의 기본 동작은 호출에 사용되지만 URL 생성에는 사용되지 않습니다. URL 규칙 구성은 다른 곳에서는 이상한 것이 없으면 100 % 작동해야합니다. . – Johnatan

+0

제공된대로 코드를 복사하여 복사했습니다. – MEM

관련 문제