加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 在Yii的另一个控制器中调用函数

发布时间:2020-12-13 18:16:24 所属栏目:PHP教程 来源:网络整理
导读:我在我的Yii应用程序中创建了2个控制器:FirstController.php和默认控制器路径中的SecondController.php. FirstController.php: ?php class FirstController extends Controller { public static function returnFunc() { return 'OK'; }} SecondController
我在我的Yii应用程序中创建了2个控制器:FirstController.php和默认控制器路径中的SecondController.php.

FirstController.php:

<?php
 class FirstController extends Controller {
  public static function returnFunc() { return 'OK'; }
}

SecondController.php:

<?php
 class SecondController extends Controller {
  public function exampleFunc() {
     $var = First::returnFunc();
  }
}

当我尝试在SecondController中执行exampleFunc()时,Yii抛出错误:

YiiBase::include(FirstController.php) [<a href='function.YiiBase-include'>function.YiiBase-include</a>]: failed to open stream: No such file or directory

调用FirstController :: returnFunc()同样不起作用.

我是OOP和Yii框架的新手.有什么问题?

我已经解决了这个问题.自动装带器不加载控制器.

它在config / main.php中:

'import' => array(
    'application.models.*','application.components.*',),

所有这些都与此有关:

'import' => array(
    'application.models.*','application.controllers.*',

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读