简体   繁体   English

在另一个控制器中调用静态方法

[英]call static method in another controller

I want to call a static method in another controller to perform some global utility-like operations (update a file, for example). 我想在另一个控制器中调用静态方法来执行一些类似于全局实用程序的操作(例如,更新文件)。 But I got a error message: 但是我收到一条错误消息:

include(AnotherController.php): failed to open stream: No such file or directory include(AnotherController.php):打开流失败:没有这样的文件或目录

at /yii/framework/YiiBase.php(421) : /yii/framework/YiiBase.php(421)处

include($className.'.php'); include($ className。'。php');

Controllers are not autoloaded by Yii. Yii不会自动加载控制器。 Add the following to your configuration file: 将以下内容添加到您的配置文件中:

// autoloading model and component classes
'import'=>array(
    'application.controllers.*',
    ...
),

Or, alternatively, just before you call a given controller, add the following line: 或者,或者,在调用给定控制器之前,添加以下行:

Yii::import('application.controllers.AnotherController');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM