YII 프레임 워크에서 URL 친화적 인 설정 방법을 자동으로 설정합니다
-
19-09-2019 - |
문제
나는 그냥 yii 프레임 워크를 배우고이 튜토리얼을 읽었습니다. yii URL을 설정하는 방법
그러나 모르겠습니다. 10 개의 컨트롤러가 있다고 가정합니다. 구성 파일에서 하나의 컨트롤러를 하나씩 정의해야합니까? 모든 컨트롤러를 위해 www.yoursite.com/yourcontroller/youraction/yourid와 같이 URL 친화적 인 설정을 설정하는 더 좋은 방법이 있습니까?
CodeIgniter가 자동으로 그렇게했다고 생각합니다 ... Yii는 어떻습니까?
해결책
/protected/config/main.php in in in in
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName' => false,
),
),
웹 루트에서 .htaccess ..
Options +FollowSymLinks
IndexIgnore */*
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
다른 팁
YII에는 자동 URL 생성이 있습니다. 예를 들어 템플릿에 해당 URL을 작성하십시오 없이 수동 경로 :
<?php echo CHtml::link('topic title',array('topic/view','id'=>$topic->id,'var'=>'123')); ?>
렌더링 된 URL은 다음과 같습니다.
/topic/view/id/1/var/123
그런 다음 action actionview () 메소드에서 우리는 다음을 사용합니다.
...
$id=$_GET['id'];
$var=$_GET['var'];
...
제휴하지 않습니다 StackOverflow