zh761324952 2016-07-22 15:54:01 5427次浏览 3条评论 1 1 0

实现URL重写兼容模式

原因:项目开始没有重写配置,后期重写,担心链接兼容问题;yii1没有兼容模式

    在扩展extensions创建文件夹rewrites  
    创建文件UrlManager.php  
    在配置文件中main.php数组import中加入
    'ext.rewrites.*',

UrlManager.php文件代码如下

<?php
/**
 * 兼容URL
 * @author Changhai Zhan
 */
class UrlManager extends CUrlManager
{
    /**
     * Parses the user request.
     * @see CUrlManager::parseUrl()
     */
    public function parseUrl($request)
    {
        if (isset($_GET[$this->routeVar])) {
            return $this->removeUrlSuffix($_GET[$this->routeVar], $this->urlSuffix);
        } elseif (isset($_POST[$this->routeVar])) {
            return $this->removeUrlSuffix($_POST[$this->routeVar], $this->urlSuffix);
        } else {
           return parent::parseUrl($request);
        }
    }
}
觉得很赞
  • 评论于 2016-10-12 17:42 举报

    根据你的方法,url并没有变化,是为何?

  • 评论于 2016-10-12 17:51 举报

    `'components'=>array(

    	// ...
    	// uncomment the following to enable URLs in path-format
    
    	'urlManager'=>array(
    		'showScriptName'=>false,
    		'urlFormat'=>'path',
    		'rules'=>array(
    			'news/<cid:\d+>'=>array('news/index','urlSuffix'=>'.xml'),
    		),
    	),
    

    `

    这个地方不需要修改么?

    3 条回复
    评论于 2016-10-17 12:30 回复
        'class' => 'UrlManager',                                    //重写方法 兼容get
    
    评论于 2016-10-17 18:11 回复

    这个加在哪里?

    评论于 2016-10-17 18:11 回复

    这个加在哪里?

  • 评论于 2016-10-19 13:50 举报

    加在数组中啊

    'urlManager' => array(
      'class' => 'UrlManager',
       //....
    )
    
您需要登录后才可以评论。登录 | 立即注册