yii url 重新
来源:互联网 发布:男女对唱的网络歌曲 编辑:程序博客网 时间:2024/05/30 02:51
test.com/nvku想生成test.com/nvku/
- 'urlSuffix'=>'/',
要更改URL格式,我们应该配置urlManager应用元件,以便createUrl可以自动切换到新格式和应用程序可以正确理解新的网址:
- 'urlManager'=>array(
- 'urlFormat'=>'path',
- 'showScriptName'=>false,
- 'urlSuffix'=>'.html',
- 'rules'=>array(
- 'posts'=>'post/list',
- 'post/<id:\d+>'=>array('post/show','urlSuffix'=>'.html'),
- 'post/<id:\d+>/<mid:\w+>'=>array('post/view','urlSuffix'=>'.xml'),
- ),
- ),
- 'posts'=>'post/list',
- echo $this->createAbsoluteUrl('post/list');
1 输出http://localhost/yii_lab/index.php/post/view
- 'post/<id:\d+>'=>array('post/show','urlSuffix'=>'.html'),
- echo $this->createAbsoluteUrl('post/show',array('id'=>998, 'name'=>'123'));
2输出http://localhost/yii_lab/index.php/post/998.html?name=123
- 'post/<id:\d+>/<mid:\w+>'=>array('post/view','urlSuffix'=>'.xml'),
- echo $this->createAbsoluteUrl('post/view',array('id'=>998, 'mid'=>'tody'));
3,输出http://localhost/yii_lab/index.php/post/998/tody.xml
- 'http://<user:\w+>.yiiblog.info/<_c:(look|seek)>'=>array('<_c>/host','urlSuffix'=>'.boylee'),
- echo $this->createAbsoluteUrl('look/host',array('user'=>'BoyLee', 'mid'=>'ny-001'));
- echo '';
- echo $this->createAbsoluteUrl('looks/host',array('user'=>'BoyLee', 'mid'=>'ny-001'));
4.输出http://BoyLee.yiiblog.info/look.boylee?mid=ny-001
http://localhost/yii_lab/index.php/looks/host/user/BoyLee/mid/ny-001
1)controller/Update/id/23
public function actionUpdate(){
$id = Yii::app()->request->getQuery('id') ; 经过处理的$_GET['id']
}
//$id = Yii::app()->request->getPost('id'); 经过处理的$_POST['id']
//$id = Yii::app()->request->getParam('id'); //CHttpRequest更多
2)public function actionUpdate($id) 这种不支持多主键,会检查一下到底GET里面有没有id,没有id就直接不允许访问
'sayhello/<name>' => 'post/hello', name是PostController actionHello($name)的参数
'post/<alias:[-a-z]+>' => 'post/view', domain/post/e文小写 其中:前面的alias是PostController actionView($alias)的参数
'(posts|archive)/<order:(DESC|ASC)>' => 'post/index', domain/posts/DESC或domain/posts/ASC
'(posts|archive)' => 'post/index', domain/posts或domain/archive
'tos' => array('website/page', 'defaultParams' => array('alias' =>'terms_of_service')),
When the URL is /tos, pass terms_of_service as the alias parameter value.
隐藏 index.php
还有一点,我们可以做进一步清理我们的网址,即在URL中藏匿index.php
入口脚本。这就要求我们配置Web服务器,以及urlManager应用程序元件。
1.add showScriptName=>false
2.add project/.htaccess
- 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
3.开启rewrite
简单的说,在main.php中简单设置urlManager,然后讲了3条规则,基本都覆盖到了。最后是隐藏index.php,请记住.htaccess位于index.php同级目录 ,而不是protected/目录。其他就简单了。
- yii url 重新
- yii url
- Yii 简化URL
- Yii url重写
- YII url美化管理
- yii 下获取url
- Yii Url重写
- yii url优化
- Yii url规则重写
- yii 常用url地址
- 【Yii】url路由
- Yii的常用URL
- Yii的URL管理
- Yii的常用URL
- Yii的常用URL
- Yii的常用URL
- YII url美化管理
- Yii url 工具类
- Hdu 1423 Greatest Common Increasing Subsequence
- 杨辉三角
- iOS开发之使用lipo命令制作模拟器与真机通用静态库
- Servlet的几种跳转
- Lua 学习开篇
- yii url 重新
- Lua简介:开发《魔兽争霸》和《愤怒的小鸟》的语言
- VBA操作文件四大方法之之四-API函数
- VBA操作文件四大方法之一--Excel对象方法
- Lua基础 初识Lua
- C# 操作Excel
- java实现简单的数字运算以及dos命令运行Java程序
- 移动div层
- idea6410 linux-3.6.6的leds移植