我正在尝试在“wamp-server”上使用 php 来练习 MVC 概念
在本地目录中,我有 index.php 页面,用于使用 alto-router 包和 routes.php 文件进行基本路由:
<?php
$router->map('GET','/test', 'Acme\Controllers\PageController@test' ,'test');
composer.json 文件是:
{
"name": "eren/eren",
"authors": [
{
"name": "Eren Ardahan",
"email": "???@???.com"
}
],
"require": {
"filp/whoops": "^1.1",
"altorouter/altorouter": "1.1.0"
},
"autoload":{
"psr-4":{"Acme\\":"src/"}
}
}
PageController.php 是
<?php namespace Acme\Controllers;
use Acme\Testing\Test;
class PageController
{
public function test(){
include(__DIR__ . "/../../views/test.php");
//---Deleted lines
$test = new Test;
$test -> test();
/---
}
}
acme 目录下的 Test.php 为:
<?php namespace Acme\Testing;
class Test{
public function test(){
echo "Working";
}
}
并且视图目录中的test.php在上面。当我删除PageController.php中注释的两行时它可以工作
<?php
echo "TEST PAGE <br>";
但是这行有一个错误:
找不到类“Acme\Testing\Test”..