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

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

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

#1 User is offline   Joblo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 703
  • 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.


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

          '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();

        else if(strpos($route,'/')===false)

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


Share this topic:

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

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