简体   繁体   English

PHP,如何有效使用类中的函数

[英]PHP, how to effectively use the functions in a class

I am using codeigniter framework. 我正在使用codeigniter框架。 let say i had controller class named myclass, this class have a function that i want to access from another controller class. 假设我有一个名为myclass的控制器类,该类具有一个我想从另一个控制器类访问的函数。

I got troubled when access the function from another controller class, i cant create an instant of this myclass class, it say class 'myclass' not found. 当从另一个控制器类访问该函数时,我感到很麻烦,我无法创建该myclass类的实例,它说未找到类'myclass'。 i dont want to use include 'myclass.php'; 我不想使用include'myclass.php'; because class myclass have __constructor method, i afraid the content inside __constructor method will conflict with another __constructor. 因为类myclass具有__constructor方法,所以我担心__constructor方法内的内容将与另一个__constructor冲突。

what the best solution for my case? 什么是最适合我的情况的解决方案?

Thanks 谢谢

CodeIgniter framework has a way to automatically loading your custom classes. CodeIgniter框架提供了一种自动加载自定义类的方法。 Look here: http://www.codeigniter.com/userguide2/general/autoloader.html 在这里查看: http : //www.codeigniter.com/userguide2/general/autoloader.html

Just make it possible for the framework to auto-load your class(es) and the problem is solved. 只要使框架自动加载您的类成为可能,问题就解决了。

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

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