gpt4 book ai didi

php - 在 Yii 中不在对象上下文中时使用 $this

转载 作者:行者123 更新时间:2023-12-02 04:21:33 25 4
gpt4 key购买 nike

当使用 EasyTabs 扩展中的 Controller 操作调用 View 文件时,我收到类似 fatal error :在第 661 行 ..\controllers\ServiceRequestController.php 中不在对象上下文中时使用 $this 的错误
我正在 View 文件中像这样调用 Controller 操作
ServiceRequestController::actionTest();
和 Controller

     public static function actionTest()  
{
$this->redirect('test');
}

如何消除这个错误?当我谷歌搜索时,我发现 $this 不能在静态方法中使用。 。所以我尝试使用
$model = new ServiceRequest();
$model->Test();
在我的 View 文件中。但它显示错误为 ServiceRequest 及其行为没有名为“actionTest”的方法或闭包。谁能帮我修复错误?提前致谢我尝试使用此链接进行修复。但我想我错了。 PHP Fatal error: Using $this when not in object context

最佳答案

定义操作时请勿使用关键字static

您可以在此处阅读有关静态方法和属性的更多信息:

http://de1.php.net/manual/en/language.oop5.static.php

关于php - 在 Yii 中不在对象上下文中时使用 $this,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16330985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com