passing parameter to onBeginRequest

How to pass a parameter to routeRequest function in SiteRouter?

I am using onBeginRequest below but I need to send a $SITEID to the Controller. How to pass in?

return array(

'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

‘onBeginRequest’ => array(‘SiteRouter’, ‘routeRequest’),

// preloading 'log' component


'preload'=>array('log'),





// autoloading model and component classes


'import'=>array(


	'application.models.*',

Is quite strange that you need to do something like that.

What exactly (pratically) are you trying to achive? Is possible that there is some easier solution to your problem.

My application run multiple sites using one Yii app, I need to pass the siteId determined at the first page like this :

C:/DomainA/index.php




  $SITEID = '2';

  include("C:/Domains/myyiiapp/front.php");



C:/DomainB/index.php




  $SITEID = '3';

  include("C:/Domains/myyiiapp/front.php");



C:/DomainC/index.php




  $SITEID = '4';

  include("C:/Domains/myyiiapp/front.php");



in front.php




$yii=dirname(__FILE__).'/../framework/yii.php';

$config=dirname(__FILE__).'/protected/config/main.php';


require_once($yii);

Yii::createWebApplication($config)->run();



in main.php




  'onBeginRequest' => array('SiteRouter', 'routeRequest'),



in SiteRouter class




         

class SiteRouter

{

  public static function routeRequest($event)

  {

    $sender = &$event->sender;


    //load site settings from database

    $siteModel = Site::model()->findbyPk( <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />??? how to get $SITEID here <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />? );

    




The $SITEID is needed at the start to load the right params from database. How do I pass $SITEID to into the SiteRouter in onBeginRequest?

Any other ways to achieve this?

I’m looking for answers too. Did you solve the above?

I want to pass the timezone for my (multi site) application specified in main.php to a function that uses set_default_timezone() to set the correct timezone before each request using onBeginRequest event handler. I could probably use app()->params too but it would be more elegant to pass it directly to the event handler in this case.

It’s a bit strange that there is no default support for TimeZone configuration already. Perhaps in the next Yii version?

Could you inherit from the Yii application for each domain and override any data in each subclass of application?