[英]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.