繁体   English   中英

Yii创建审核跟踪; 控制器到另一个控制器

[英]Yii Creating an audit trail; Controller to another Controller

我正在使用Yii php为项目创建审计跟踪模块,我是一个新手。.众所周知,审计跟踪与历史记录,事务日志的创建有关...我已经创建了一个模型审计跟踪,并为其生成一个控制器和一个单独的模型。 (当然使用gii)

我的问题在于如何实际创建条目或跟踪(日志,历史记录,我不知道对不起= 3)

我的AuditTrailController有一个动作:

class AuditTrailController extends Controller{

    public function actionCreate()
    {
    //do create the trail   
    }

}

我的计划是从整个项目中所有模块的每个其他控制器调用actionCreate(),例如:

class StudyController extends Controller {

        public function addRecord(){
        //add some record


        //---> i want to call the acionCreate() from the AuditTrailController from here
        //to create an entry telling that the some user "user" at time "time"
        //performed an "add" operation..
        }

        public function updateRecord(){
        //update some record


        //---> i want to call the acionCreate() from the AuditTrailController from here
        //create an audit entry telling the user "updated"
        }

}

-Yii:app()不能解决问题..(或我错误地使用了它)。

我已经搜索了很多答案,但是他们说从一个控制器中调用另一个控制器是“邪恶的”。我看到像使用Component..other这样的术语,应该在模型中完成...但是我不知道。我是OOP和Yii的新手,所以我在这里很挣扎。.谢谢我。

您可以通过这种方式在另一个控制器中调用动作

//这里是您的行动控制器

class AuditTrailController extends Controller
{

    public function actionCreate()
    {
    //do create the trail   
    }

}

//在此处您要使用动作的控制器

class StudyController extends Controller {

        public function addRecord(){
               $controller = new AuditTrailController($this->id);
               $controller->actionCreate();
        }
}

并且不要忘记添加以配置此行以导入

    'application.controllers.*',

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM