Yii Framework Forum: $Controller->Createurl() - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

$Controller->Createurl() Rate Topic: -----

#1 User is offline   Joblo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 664
  • Joined: 12-September 10
  • Location:Austria

Posted 16 April 2013 - 02:45 AM

The createUrl() method of a controller doesn't take care of the Yii::app()->controllerMap.


Example:

I have mapped a module-controller to the root: moduleId = 'mysitemodule'

  'controllerMap'=>array(
          'site' => 'mysitemodule.controllers.DefaultController'    
   )  



defaultcontroller->getId() will return 'site', because the CWebApplication::createController takes care about the controllerMap and changes the controllers Id.

defaultcontroller->createUrl('actionid') creates a invalid actionUrl 'mysitemodule/site/actionid':
A 'mysitemodule.controllers.SiteController' will not be found.

A possible solution:

The CController::createUrl() method should not add the moduleId if the controller is mapped to the root.

 public function createUrl($route,$params=array(),$ampersand='&')
    {       
        $controllerId = $this->getId();

        if($route==='')
            $route=$controllerId.'/'.$this->getAction()->getId();
        else if(strpos($route,'/')===false)
            $route=$controllerId.'/'.$route;

        //don't add the module id if the controller is mapped
        if(!isset(Yii::app()->controllerMap[$controllerId]) && $route[0]!=='/' && ($module=$this->getModule())!==null)
           $route=$module->getId().'/'.$route;
        return Yii::app()->createUrl(trim($route,'/'),$params,$ampersand);
    }


0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users