Reputation: 8937
I would like to log which users visited the site today. To do this I have to handle user visit at any page I have on the site.
What is common entry point (code, which executes on any visit to any page)?
Upvotes: 1
Views: 658
Reputation: 2267
I guess if you want to log which users visited site then you should implement this functionality in user
component (CWebUser
by default). You can extends this calss and specify it in config for user component:
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
'class'=>'MyWebUser',
),
Upvotes: 3
Reputation: 1191
Also you can create class BaseController extends CController, and use init method. For example:
class BaseController extends CController
{
public function init()
{
$this->loggedUserId = Yii::app()->user->getId();
$this->isLogged = !empty($this->loggedUserId);
if ($this->isLogged) {
// some log actions
}
return parent::init();
}
}
Upvotes: 4
Reputation: 2150
Assuming you are talking about Yii 1.1
There are onBeginRequest and onEndRequest events you could attach your logic on:
Example (in an appropiate file, index.php/custom loader script, simple)
Yii::app()->onBeginRequest = function(CEvent $event) { handle_event($event); };
Or attach a custom behaviour to that event in your config:
'behaviors' => array(
'onbeginRequest' => array(
'class' => 'application.components.AnalyticsBehaviour',
)
)
and handle in the behaviour.
Upvotes: 1