Home > PHP Framework > YII > body text

How to re-url in yii

王林
Release: 2019-12-07 11:48:51
Original
15421 people have browsed it

How to re-url in yii

1. Url re-rules

1、将项目的地址修改成静态模式(伪静态===Url路由管理):
       a)Index.html  ===  index.php?r=index/index
       b)Cate-1.html  ===  index.php?r=article/list&cid=1
       c)Art-1.html   ===  index.php?r=article/index&aid=1

d)想完成上述功能:
     i.需要有apache功能模块的支持 url重写模块
     ii.修改apache配置文件,apache安装目录/Conf/httpd.conf
           1.LoadModule rewrite_module modules/mod_rewrite.so
           2.AllowOverride All
     iii.重启apache,使其修改生效

e)使用yii框架的URL路由功能:
i.隐藏入口文件
1.编辑.htaccess文件
   a)RewriteEngine On
   b)RewriteCond %{REQUEST_FILENAME} !-f
   c)RewriteCond %{REQUEST_FILENAME} !-d
   d)RewriteRule . index.php

2.编辑项目配置文件
bbs/protected/config/main.php
   a)'urlManager'=>array(
i.'urlFormat'=>'path',//开启pathinfo格式
ii.'showScriptName'=>false,//index.php 隐藏入口文件
iii.‘urlSuffix’=>’.html’,
iv.'rules'=>array(
    1.‘index’=>’index/index’,
    2.‘cate-<cid:\d+>’=>’article/list’,
    3.‘art-<aid:\d+>’=>’article/index’,
v.),
b)),
Copy after login

2. $this->createUrl method of Yii framework

$this-> of Yii framework The createUrl method will automatically generate corresponding hyperlinks based on url rules. Therefore, during the project development process, we need to use createUrl to help us generate all hyperlinks.

Recommended related articles and tutorials: yii framework

The above is the detailed content of How to re-url in yii. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template