Hi,
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/cp.host4hope.com',
),
The absolute URL I need to generate is
'https://localhost/project_browser/html/cp.host4hope.com/index-local.php/user/verify/code/{$verification_code}'
echo Yii::app()->createAbsoluteUrl('user/verify', array('code' => $verification_code));
//outputs
//Notice the reference to the yiic console script file.
'https://localhostC:\xampplite\htdocs\project_browser\code\private\yiic.php?r=user/verify&code=df35da088053ec704a3d58405c0a8818'
Any ideas of how to setup hostInfo and baseUrl correctly for a console app?
Cheers,
Matt
gusnips
(Gustavo)
July 12, 2011, 3:54pm
2
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
Gustavo
You’re a bloody genius!
Final solution:
'request' => array(
'hostInfo' => 'https://localhost/project_browser/html/cp.host4hope.com',
'baseUrl' => '/project_browser/html/cp.host4hope.com',
'scriptUrl' => 'index-local.php',
),
Matt
befi
(Bernhard Finkbeiner)
February 23, 2012, 8:04pm
4
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',
),
doughty
(Thexesyproject)
April 2, 2013, 12:22am
6
jellysandwich:
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?