CHtml::normalizeUrl() a bit advice

CHtml.php r1540

line: 971


public static function normalizeUrl($url)

{

    if(is_array($url))

    {

        if(isset($url[0]))

        {

            if(($c=Yii::app()->getController())!==null)

                $url=$c->createUrl($url[0],array_splice($url,1));

            else

                $url=Yii::app()->createUrl($url[0],array_splice($url,1));

        }

        else

            $url='';

    }

    return $url==='' ? Yii::app()->getRequest()->getUrl() : $url;

}



change to:


public static function normalizeUrl($url)

{

    if(is_array($url))

    {

        if(isset($url[0]))

        {

            $params = array_splice($url,1);

            if(isset($params[0]) && is_array($params[0]))

            {

                $params = $params[0];

            }


            if(($c=Yii::app()->getController())!==null)

                $url=$c->createUrl($url[0],$params);

            else

                $url=Yii::app()->createUrl($url[0],$params);

        }

        else

            $url='';

    }

    return $url==='' ? Yii::app()->getRequest()->getUrl() : $url;

}

it can be use like:


Html::link('link text', array('controllerId/actionId', array_merge($_GET, array('lang'=>$lang));

i think it will be useful~ :rolleyes:

I notice you open a lot of threads lately proposing changes to the Yii source. No problem of course, but I miss any motivation. What is the problem you’re trying to solve? What effect will your change have? Is it useful for everyone or maybe just for your own project? If you try to be a little more descriptive in your proposed changes, it’s easier to have a serious discussion about it :)

thanks~

we use the Html::link() present:

Html::link(‘link text’, array(‘controllerId/actionId’, ‘id’=>3, ‘name’=‘petter’));

when we have url params is array, it can not push in Html::link() params to build the link tag~

so, i try to solve this problem, if the url second parameter is array,

set it be url params, rather thank array_slice($url,1);

and this modification is downward compatibility