我创建了一个结构来启动我的php框架并没有任何设法使它工作,因为逻辑上它应该可以实例化“require”中指示的类但我无法从字符串动态实例化它们:< / p>
$require_module = 'contact';
$instance = new $require_module;
composer.json
{
"require": {
"illuminate/database": "*",
"illuminate/routing": "~5.1.16",
"illuminate/events": "~5.1.16"
},
"autoload": {
"psr-4": {
"System\\" : "system/libs/"
}
}
}
的index.php
<?php
require_once 'vendor/autoload.php';
require_once './system/sys_functions.php';
// Load all app modules controller into modules folder
foreach (read_modules() as $require_module){
require "./modules/$require_module/controller.php";
$instance = new $require_module;
// output Fatal error: Uncaught Error: Class 'contact' not found in /var/www/html/fsib/test.php:15 Stack trace: #0 {main} thrown in /var/www/html/fsib/test.php on line 15
}
?>
模块/接触/ Controller.php这样
<?php
namespace System\Core;
Class contact extends Fsib_controller
{
}
?>
系统/库/ fsib_controller.php
<?php
namespace System\Core;
class Fsib_controller
{
}
?>
答案 0 :(得分:0)
这是解决方案,我可以修复它。
<?php
require_once 'vendor/autoload.php';
require_once './system/sys_functions.php';
// Load all app modules controller into modules folder
foreach (read_modules() as $require_module){
require "./modules/$require_module/controller.php";
$namesp = "System\Core\\";
$className = $module_name;
$load = $namesp.$className;
$instance = new $load;
// output Fatal error: Uncaught Error: Class 'contact' not found in /var/www/html/fsib/test.php:15 Stack trace: #0 {main} thrown in /var/www/html/fsib/test.php on line 15
}
?>