Hello everyone,
I tried to build a URL in a console application like this:
$url = Yii::app()->getUrlManager()->createUrl('route/name', $_GET_PARAMS);
but "echo $url" I got:
./route/name/xxxxx
the "http://hostname" was missed.
How can I build a full url in console?
Many thanks!
Page 1 of 1
How to build URL in console application?
#2
Posted 12 March 2010 - 03:57 PM
Hi, welcome to forum.
One solution is to use Parameterizing Hostnames (at the bottom). When you then create an url, it will contain the full host info. A problem is that the config is a little bloated and when you change your domain, you must change all url rules. You may do something like this for flexibility:
Another solution is to just add the correct host:
You can define the params array in config. If you want to automate this, you may create a special UrlManager component for the console application that will auto-prefix a created url with the correct host.
One solution is to use Parameterizing Hostnames (at the bottom). When you then create an url, it will contain the full host info. A problem is that the config is a little bloated and when you change your domain, you must change all url rules. You may do something like this for flexibility:
// Use different hosts for debugging and production + easy to modify later
$host = YII_DEBUG ? 'http://localhost' : 'http://example.com';
'components' => array(
...
'urlManager' => array(
...
'rules' => array(
"{$host}" => 'site/index',
"{$host}/contact" => 'site/contact',
...
),
),
...
),
Another solution is to just add the correct host:
$url = Yii::app()->params['host'] . Yii::app()->request->createUrl('site/index');
You can define the params array in config. If you want to automate this, you may create a special UrlManager component for the console application that will auto-prefix a created url with the correct host.
Share this topic:
Page 1 of 1

Help












