题
我刚开始学习Yii框架和阅读本教程 有关 YII如何设置网址
,但我不知道,假设我有10个控制器,I应该限定一个通过在配置文件中的一个控制器? 有没有设置URL一个更好的办法友谊赛www.yoursite.com/yourController/yourAction/yourID所有控制器?
我觉得笨做到了自动...怎么样警予?
解决方案
在/protected/config/main.php添加..
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName' => false,
),
),
在Web根一个.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
其他提示
有自动URL生成在Yii中太。例如只写在你的模板,例如URL的没有手动路线:
<?php echo CHtml::link('topic title',array('topic/view','id'=>$topic->id,'var'=>'123')); ?>
和呈现的网址将是如下:
/topic/view/id/1/var/123
然后,在我们的动作的actionView()方法中,我们使用这些参数:
...
$id=$_GET['id'];
$var=$_GET['var'];
...
不隶属于 StackOverflow