Set hostInfo and baseUrl


I’m trying to generate absolute urls in a console application. Qiang said I need to set the request->hostInfo and request->baseUrl properties.

This is what my console config looks like

'request' => array(

            'hostInfo' => 'https://localhost',

            'baseUrl' => '/project_browser/html/',


The absolute URL I need to generate is


echo Yii::app()->createAbsoluteUrl('user/verify', array('code' => $verification_code));


//Notice the reference to the yiic console script file.


Any ideas of how to setup hostInfo and baseUrl correctly for a console app?



I took a good look at CHttpRequest and as you are using “showScriptName” option in the urlManager, you also must set request’s “scriptUrl” option to “index.php”

tell me if it works


You’re a bloody genius!

Final solution:

'request' => array(

            'hostInfo' => 'https://localhost/project_browser/html/',

            'baseUrl' => '/project_browser/html/',

            'scriptUrl' => 'index-local.php',



I tried setting the request properties in my console config, but all I get is "exception ‘CException’ with message ‘property "CConsoleApplication.request is read-only.’

I am using yii 1.1.10 - any ideas? I am probably overlooking something…

edit: never mind, found it. I didn’t put the “request” part into the “components” part… silly me

I seem to be having trouble with this. Setting up on my localhost (http://localhost/yii-project)

with showScriptName = false

'request' => array(

            'hostInfo' => 'http://localhost',

            'baseUrl' => '/yii-project',

            'scriptUrl' => 'index-test.php',


The above did not work. The below, however, did …

"request" => array(

                'hostInfo' => 'http://localhost',

                'baseUrl' => '/yii-project/index-test.php',


is it possible to have one config that works locally as we as remotely?