Checking route in static, controller-independed function

Hi there,

I have to send currently logged-in user to DB, in every request (let’s drop discussions on performance here, it was not my idea of such solution! :]).

For this purpose, I’ve followed Yii guide and overloaded onBeginRequest with my own public static function beginRequest(), which code is placed in Controller.php - an abstract, base class for all my controllers.

It checks, if DB is accessible (if(Yii::app()->db->active) and, if user is not a guest (if(!Yii::app()->user->isGuest)) and if both conditions are met, it uses PL/SQL function call to do, what it is indented to do. If DB is not active, it throws a nice exception.

No, I want to customize this function to check, what is the current route to turn off DB checking and ID logging in case user has selected account/logout route to log out from application.

But I have no idea, how could I do this, since beginRequest is (and has to be) a static function, controller independent, so standard methods of checking router (using controller) fails here.

Thanks in advance for any idea,

Trejder

Sounds like you’re auditing web users in an Oracle database. If you’re using oci, are you setting oci_set_client_identifier? If so, this method doesn’t make a separate trip to the database to set info. Check out this article: PHP Web Auditing, etc.

If I’m totally off base, you could create a separate base controller that does not include the overloaded beginRequest(). Then put your logout action in a controller extended from the second base controller. Just a thought.

This maybe can help you:




<?php


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

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


require_once($yii);


$app = Yii::createWebApplication($config);


$onBeginRequest = function ($event) {

        // TODO

};


$onEndRequest = function ($event) {

        // TODO

};


Yii::app()->onBeginRequest = $onBeginRequest;


Yii::app()->onEndRequest = $onEndRequest;


$app->run();




I’m just passing current user ID to DB as requested by DB’s developer and to the PL/SQL function he provided. I’m a total Oracle newbie and all these things are a little bit maddnes for me! :]

That sounds like a good idea. I’ll investigate it further. Thanks!

Hi,

Either I’m missing something, or this is just another approach to specify own onBeginRequest and onEndRequest, but your code does not answer the question, how to differentiate, which routes are being called in such requests.

Trejder

sensorario, are you suggesting that since these can be changed at runtime, that Trejder can assign new values at the beginning of the logout action (or anywhere else he wanted)?

Hi Trejder,

I’ve just been facing the same problem of yours (at least I think so) and I found the following solution to get the current route while onBeginRequest event is being fired:


$route = Yii::app()->urlManager->parseUrl(Yii::app()->request);

Yii documentation link: UrlManager