CWidget should have a createUrl(..) implementation?

After some research in the source and reading the api I’d like to discuss if the CWidget class shouldn’t have a createUrl() implementation like CController but appending to the action automatically the $prefixUrl. I think it could be very useful

What do you think?

You can either use Yii::app()->createUrl or $this->getController()->createUrl() inside the widget class.

Sure, but for commodity when you’re in widget view, usually referring to widget contributed actions (actions declared in function actions() {…}, that will be prefixed in main controller), maybe people would like to write $this->creteUrl(‘widgetAction’);

Well, currently I’m missing that functionality and indeed I have written a superclass like this:

class Widget extends CWidget {

  public function createUrl($action,$params=array(),$ampersand='&') {

    return $this->getController()->createUrl($this->actionPrefix.$action, $params, $ampersand);



I have defined a function in a widget

private function createUrl($input) {

    return Yii::app()->createUrl($input);


Usage is simple: $this->createUrl (‘controllerName/actionName’)