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

标签 php yii yii-extensions yii-components yii-events

当使用 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/

相关文章:

PHP Yii - ActiveDropDownList() 默认选中

php - 更改kartik dynagrid操作列

php - 如何使用 importcsv 插件读取 CSV 文件数据

PHP preg_replace : remove punctuation from beginning and end of string

testing - 如何在 Yii 中对 Controller 进行单元测试

javascript - 在 VueJS 中注入(inject) PHP 数据的正确方法是什么?

php - $facebook->api ('/me' ) 返回 NULL

yii - 如何配置 yiibooster

php - 如何从多个查询中获取多个结果

PHP 找不到保存处理程序内存缓存