Is it possible to output profile info in a console application. It is enabled in my console config correctly and I am using Yii::beginProfile() and Yii::endProfile(). I now need to capture the results some how and display them in the console. Am I missing something? Is this even possible?
This is the thing that aop can handle it easily and it is for this kind of purpose.
So for yii. If you go to CController class there is two methods:
/**
* This method is invoked right before an action is to be executed (after all possible filters.)
* You may override this method to do last-minute preparation for the action.
* @param CAction $action the action to be executed.
* @return boolean whether the action should be executed.
*/
protected function beforeAction($action)
{
return true;
}
/**
* This method is invoked right after an action is executed.
* You may override this method to do some postprocessing for the action.
* @param CAction $action the action just executed.
*/
protected function afterAction($action)
{
}
What I would do is this:
In Controller class in your component package, I would override with those two methods:
/**
* This method is invoked right before an action is to be executed (after all possible filters.)
* You may override this method to do last-minute preparation for the action.
* @param CAction $action the action to be executed.
* @return boolean whether the action should be executed.
*/
protected function beforeAction($action)
{
echo "Begin:";
echo "method is:".$action->getId();
echo "controller is:".$action->getController()->getId();
return true;
}
/**
* This method is invoked right after an action is executed.
* You may override this method to do some postprocessing for the action.
* @param CAction $action the action just executed.
*/
protected function afterAction($action)
{
echo "End:";
echo "method is:".$action->getId();
echo "controller is:".$action->getController()->getId();
}
So for any Controller that Extended from the Controller class, the framework will run the above overriden methods and print it. You are going to change the output according to your taste, as long as you have $action object, You have many information.
make sure you are returning true from beforeAction() method, if false yii does not run your real action(I guess that can be handy for security interseption).