嗨,我是新來的苗條我停留在這個任何人的幫助,請修身贖回UserController中不存在的RuntimeException
routes.php文件
$app->get('/', 'UserController:index');
dependencis.php
$container['src\UserController'] = function ($container) {
return new \src\UserController($container->get('settings'));
};
UserController.php
namespace App\Controllers;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use App\src\Controller;
class UserController extends Controller {
public function index(Request $request, Response $response) {
return $this->db;
}
}
和Controller.php這樣
namespace App\src;
class Controller {
protected $container;
public function __construct($c) {
$this->container = $c;
}
public function __get($property) {
if($this->container->has($property)) {
return $this->container->get($property);
}
return $this->{$property};
}
}
您確定應該在容器中返回'new \ src \ UserController()',而不是'new \ App \ src \ UserController'嗎? –
$ container ['src \ UserController'] = function($ container){ return new \ src \ UserController(); }; 這裏通過改變路徑\ src \ UserController()來更新它的大部分內容。和 return new \ src \ UserController($ contianer); –
嗨@ShahzadNasir,我有一個看起來像你的問題。我可以從這裏獲得幫助:http://stackoverflow.com/questions/43449493/slim-framework-routing-http-requests-to-static-class-methods。謝謝 – red