Request Variable In Application Component

I am using a custom application component referenced in config/main.php and would like to use $_REQUEST variables as parsed from CUrlManager like so:




'preload'=>array(

        'location'

),






'components'=>array(

	'urlManager'=>array(

		'class'=>'application.components.UrlManager',

		'rules'=>array(                                

				'<country:\w{2}>/<city:\w+>/<controller:\w+>'=>'<controller>',

		),

	),

	'location' => array(

		'class' => 'application.components.LocationComponent',

		'urlVars' => array(

			'country'   => $_REQUEST['country'],

			'city'      => $_REQUEST['city']

		)

	),

	...



Everything is working except $_REQUEST array is empty during the LocationComponent init() function.

Any suggestions?

Have you tried defining the variables before and then using them there as




$country=isset($_REQUEST['country'])?$_REQUEST['country']:'PK',

$city=isset($_REQUEST['city'])?$_REQUEST['city']:'SKT',



Moreover,

you can also do this in your urlVars as what I understand is that you want to do jobs country specific.

You can do this in your init function of the location component as




public function init(){

       $this->country=$_REQUEST['country'];

       $this->city=$_REQUEST['city'];

}



Thanks for the reply.

I ended up removing the urlVars=>array() from config/main.php and removed ‘location’ from preloader.




    public function init () {

        if(

            isset($_REQUEST['country']) && isset($_REQUEST['city']) &&

            strlen($_REQUEST['country']) > 0 && strlen ($_REQUEST['city']) > 0

            ) { .... }

    }



The next time Yii::app()->location was referenced it checked the $_REQUEST variable.