[英]Yii Creating an audit trail; Controller to another Controller
I'm creating an audit trail module for a project using Yii php, and i'm quite a newbi.. and as we all know audit trail is concerned with the creation of history, transaction logs... i've created a model for the audit trail and generated a controller as well as a separate model for it. 我正在使用Yii php为项目创建审计跟踪模块,我是一个新手。.众所周知,审计跟踪与历史记录,事务日志的创建有关...我已经创建了一个模型审计跟踪,并为其生成一个控制器和一个单独的模型。 (Using gii of course)
(当然使用gii)
My problem lies with how to actually create an entry , or a trail (log, history, i don't know the term sorry =3) 我的问题在于如何实际创建条目或跟踪(日志,历史记录,我不知道对不起= 3)
I have my AuditTrailController with an action: 我的AuditTrailController有一个动作:
class AuditTrailController extends Controller{
public function actionCreate()
{
//do create the trail
}
}
My plan is to call the actionCreate() from every other controllers from all over the modules in the whole project like say: 我的计划是从整个项目中所有模块的每个其他控制器调用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"
}
}
-The Yii:app() doesn't do the trick..(or ive used it wrongly).. -Yii:app()不能解决问题..(或我错误地使用了它)。
I've searched for many answers but they say it's "evil" to call another controller from one..i saw terms like using Component..other say it should be done in the model... but i have no idea.. i'm new in OOP and Yii so i'm in a struggle here.. help me out thanks.. but if the above is possible then a sample code would be really helpful thanks! 我已经搜索了很多答案,但是他们说从一个控制器中调用另一个控制器是“邪恶的”。我看到像使用Component..other这样的术语,应该在模型中完成...但是我不知道。我是OOP和Yii的新手,所以我在这里很挣扎。.谢谢我。
you can call action in another controller in this way 您可以通过这种方式在另一个控制器中调用动作
//here is you controller with action //这里是您的行动控制器
class AuditTrailController extends Controller
{
public function actionCreate()
{
//do create the trail
}
}
//here controller where you want to use your action //在此处您要使用动作的控制器
class StudyController extends Controller {
public function addRecord(){
$controller = new AuditTrailController($this->id);
$controller->actionCreate();
}
}
And don't forget add to config this line to import 并且不要忘记添加以配置此行以导入
'application.controllers.*',
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.