I want to run some code in the onBeginRequest event.
Where do I do that? I assume I am not suppose to add this in the core library code.
I am a totally noob in Yii
I want to run some code in the onBeginRequest event. Where do I do
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want to use onBeginRequest and onEndRequest you can do it by adding the next lines into your config file:
or you can do it inline
where
Yis a classname andgetStatsandwriteStatsare methods of this class.Now imagine you have a class
Ydeclared like this:So on every request both methods will run automatically. Of course you can think “why not simply overload onBeginRequest method?” but first of all events allow you to not extend class to run some repeated code and also they allow you to execute different methods of different classes declared in different places.
So you can add
at any other part of your application along with previous event handlers and you will get run both
Y->writeStatsandYClass->someMethodafter request processing. This with behaviors allows you create extension components of almost any complexity without changing source code and without extension of base classes of Yii.