1. Go to this page and download the library: Download guanguans/yii-goaop library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
php
namespace frontend\aspects;
use Go\Aop\Aspect;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Annotation\Before;
use Go\Lang\Annotation\After;
use Yii;
class LoggingAspect implements Aspect
{
/**
* Method that will be called before real method
* @param MethodInvocation $invocation Invocation
* @Before("execution(public frontend\controllers\SiteController->*Index(*))")
*/
public function beforeMethodExecution(MethodInvocation $invocation)
{
file_put_contents(Yii::$app->getRuntimePath().'/logs/logging.log', 'this is a before method testing.'.PHP_EOL, FILE_APPEND);
}
/**
* Method that will be called after real method
* @param MethodInvocation $invocation Invocation
* @After("execution(public frontend\controllers\SiteController->*Index(*))")
*/
public function afterMethodExecution(MethodInvocation $invocation)
{
file_put_contents(Yii::$app->getRuntimePath().'/logs/logging.log', 'this is a after method testing.'.PHP_EOL, FILE_APPEND);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.