0
我在App \ foldername中创建了自定义类,以下是2个类。孩子班可以很多。如何解决未找到的类
App\foldername\ChildCls
App\foldername\MyMainCls
ChildCls.php
namespace App\foldername;
class ChildCls {
}
MyMainCls.php
namespace App\foldername;
class MyMainCls{
function validateGroupValues($groupname){
//here $groupname will be class name that is "ChildCls" that will be dynamically loaded
$ob = new $groupname();
}
}
在控制器
use App\Diamond_Search\MyMainCls;
class MySearchController extends Controller
{
$ob = new MyMainCls();
$ob->validateGroupValues('test');
}
但我得到以下错误
类“ChildCls”未找到
如果我使用静态$ OB =新\ APP \文件夹\ ChildCls那么它工作正常,但我不能提到它静态因为会有很多儿童类,我必须动态调用。
那么在这种情况下可能的解决方案是什么?
'$ clsname =“\ App \ foldername \ $ groupname”;新的$ clsname()'? – apokryfos