Yii::app()->request->baseUrl need clarification

Hello,

I am currently using the UrlManager described in the Yii doc, with .htaccess and configuration file.

I have a trouble, since I am using the UrlManager and call Yii::app()->request->baseUrl in the config params It always return http://localhost despite of http://localhost/domain.name/

Here the following files:

main.php:



		'urlManager'=>array(


			'showScriptName'=>false,


			'urlFormat'=>'path',


			'urlSuffix' => '.html',


			'rules'=>array(


            ),


      ),

.htaccess:

Options +FollowSymLinks


IndexIgnore */*


RewriteEngine on





# if a directory or a file exists, use it directly


RewriteCond %{REQUEST_FILENAME} !-f


RewriteCond %{REQUEST_FILENAME} !-d





# otherwise forward it to index.php


RewriteRule . index.php

and in params.php:

<?php


return array(


	// using Yii::app()->params['paramName']


		'imageCouleurPath'			=>		Yii::app()->request->baseUrl.'/images/couleurs/',


		'adminEmail'				=>		'webmaster@example.com',


		'imageSetIconsPath'			=>		Yii::app()->request->baseUrl.'/images/set_icons/',


		'imageSetIconsThumbPath'	=>		Yii::app()->request->baseUrl.'/images/set_icons/thumb/',


);

Any ideas please? I am stuck :confused:

This is caused by your server configuration. Please print_r($_SERVER) and see what it is.

Thank you for your answer Qiang.

I have a look what you asked. Did not find anything suspicious which may be the cause of this problem.

Here the result of the print_r:

Array


(


    [REDIRECT_STATUS] => 200


    [HTTP_HOST] => localhost


    [HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)


    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8


    [HTTP_ACCEPT_LANGUAGE] => fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3


    [HTTP_ACCEPT_ENCODING] => gzip,deflate


    [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7


    [HTTP_KEEP_ALIVE] => 300


    [HTTP_CONNECTION] => keep-alive


    [HTTP_REFERER] => http://localhost/domain/accueil.html


    [PATH] => C:Program FilesPC Connectivity Solution;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:Program FilesQuickTimeQTSystem;C:wampwwwyiiframework;C:wampbinphpphp5.2.6;C:wampwwwZendFramework-1.8.0bin;C:Program FilesSubversionbin;C:Program FilesTortoiseSVNbin


    [SystemRoot] => C:WINDOWS


    [COMSPEC] => C:WINDOWSsystem32cmd.exe


    [PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH


    [WINDIR] => C:WINDOWS


    [SERVER_SIGNATURE] => 


    [SERVER_SOFTWARE] => Apache/2.2.8 (Win32) PHP/5.2.6


    [SERVER_NAME] => localhost


    [SERVER_ADDR] => 127.0.0.1


    [SERVER_PORT] => 80


    [REMOTE_ADDR] => 127.0.0.1


    [DOCUMENT_ROOT] => C:/wamp/www/


    [SERVER_ADMIN] => admin@localhost


    [SCRIPT_FILENAME] => C:/wamp/www/domain/index.php


    [REMOTE_PORT] => 1133


    [REDIRECT_URL] => /domain/accueil.html


    [GATEWAY_INTERFACE] => CGI/1.1


    [SERVER_PROTOCOL] => HTTP/1.1


    [REQUEST_METHOD] => GET


    [QUERY_STRING] => 


    [REQUEST_URI] => /domain/accueil.html


    [SCRIPT_NAME] => /domain/index.php


    [PHP_SELF] => /domain/index.php


    [REQUEST_TIME] => 1242567439


)


Based on your $_SERVER info, 'baseUrl' should be '/domain'.

Hmmm I don't understand.

Wen I am calling Yii::app()->request->baseUrl in my view I see /domain.name.

But when I am trying to do that way in the main config:

	  'params'=>array(


		'imageCouleurPath'			=>		Yii::app()->request->baseUrl.'/images/couleurs/',


		'adminEmail'				=>		'webmaster@example.com',


		'imageSetIconsPath'			=>		Yii::app()->request->baseUrl.'/images/set_icons/',


		'imageSetIconsThumbPath'	=>		Yii::app()->request->baseUrl.'/images/set_icons/thumb/',


	),

And show the variable e.g. Yii::app()->params['imageCouleurPath'] in the view it shows me "/images/couleurs/".

Do I am doing something wrong? ???

Do not access app components in app config because at that time, the components are not configured and available yet.

You may use dirname($_SERVER['SCRIPT_NAME']) here to indicate the base URL.

Ok thank you very much Qiang.