php - Yii 2 有 AOP 吗?

标签 php yii yii2 aop typo3-flow

我想知道每个 Action 执行了多少时间。最简单/正确的方法是使用 AOP。

我想要这样的东西:

/**
 * @FLOW3\Before("method(.*->action.*())")
 */
 public function markFirstTimeTag() {
// Do something here.
 }

 ...

 /**
 * @FLOW3\After("method(.*->action.*())")
 */
 public function markSecondTimeTag() {
// Do something here.
 }

我读到了 FLOW3我喜欢这个框架。但这本身就是一个全栈框架。

Yii 2有AOP模式的实现吗?

最佳答案

我通常使用Logging分析我的代码。

Yii::trace('starting some event');
foreach(..)
{
    ...
}
Yii::trace('some event done');

可以在调试栏的日志部分找到此跟踪。

这可以与 beforeAction() 结合使用和 afterAction() (未测试)

public function beforeAction($action)
{

    if (!parent::beforeAction($action)) {
        return false;
    }

    Yii::trace($action->id.' started');

    return true; // or false to not run the action
}

public function afterAction($action, $result)
{
    $result = parent::afterAction($action, $result);
    Yii::trace($action->id.' ended');
    return $result;
}

我还找到了Performance Profiling在文档中,但我没有尝试任何解决方案。

关于php - Yii 2 有 AOP 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38147028/

相关文章:

php - 克服跨域问题

Yii 框架 urlManager 重写规则

php - 为 yii2 设置 yii2-jeasyui

mysql - Yii2:如何从 'date' db 列中按 'time' 和 'datetime' 进行过滤

Php排行榜问题

php - 根据多个值对多维数组进行排序

php - Yii 1.1.16 - renderPartial() 在输出开始处添加一个空格

jquery - Yii2 在日期选择器中设置开始日期

php - 删除sql表数据然后插入多个可变数量的行

php - 在 Yii Framework 中处理输出