I'm new to web development, and I've spent hours trying to understand Yii and how it handle's URLs. I've read scores of tutorials and still don't understand it.
I'm trying to set the URL for a button widget, for a menu widget, for a Controller Action, and for a basic HTML link. It appears that Yii handles all of this routing differently, and I can't get it to work.
Here is one example. I need to get from a page in the protected/views/site
folder to a module in protected/modules
. ALL of the following commands give me the CException error SiteController cannot find the requested view [...] .../yii/framework/web/CController.php(878)
file when issuing the following command ...
$this->render(Yii::app()->createURL('module/action'));
$this->render(Yii::app()->createURL('/module/action'));
$this->render(Yii::app()->createAbsoluteURL('module/action'));
$this->render(Yii::app()->createAbsoluteURL('/module/action'));
$this->render('module');
$this->render('/module');
$this->render('//module')
$this->render('module/action');
$this->render('/module/action');
I thought I was getting this error because createURL()
gives me /app/index.php/module/action
. Instead, I want http://mysite/app/index.php/module/action
. Thanks to @Jonnny, I was able to get the full URL with createAbsoluteURL()
.
The problem is that I am still getting the same error. If I type http://mysite/app/index.php/module/action
, I get the module I want, but if I try to render the page through Yii, I get the CException error.
The frustrating thing is that I can move between controllers quite easily in other areas of Yii. For example, if I set parameters to a YiiBooster widget with something like ...
array('label' => 'Menu Option',
'url' => array('/controller/action')
... I get routed to http://mysite/app/index.php/controller/action
no matter what controller I started with. The URL pattern for a controller/action is the same URL pattern for a module/action, so why can't Yii take me to the module/action?
UPDATE:
Until I can understand Yii better, I am using a solution found on http://www.highnd.com/articles/yii-framework/yii-url-links-and-redirection. I can now access a module using the command:
$this->redirect(Yii::app()->createAbsoluteURL('module'));