2017-06-14 61 views
0

我註冊一個控制器與容器,但它似乎無法正常工作,因爲它不符合正確的位置。PHP Slim 3 Framework - 我可以在哪裏放置我的控制器文件?

\苗條的\ src \ routes.php文件

<?php 
// Routes 
$app->get('/dd', 'App\controllers\HomeController:home'); 

\超薄\軟件\控制器\ HomeController.php

<?php 
class HomeController 
{ 
    protected $container; 

    // constructor receives container instance 
    public function __construct(ContainerInterface $container) { 
     $this->container = $container; 
    } 

    public function home($request, $response, $args) { 
     // your code 
     // to access items in the container... $this->container->get(''); 
     return $response; 
    } 

    public function contact($request, $response, $args) { 
     // your code 
     // to access items in the container... $this->container->get(''); 
     return $response; 
    } 
} 

我的項目文件夾結構:

\slim 
  \public 
    index.php 
    .htaccess 

  \App 
    \controllers 
      HomeController.php 

  \src 
    dependencies.php 
    middleware.php 
    routes.php 
    settings.php 

  \templates 
    index.phtml 

  \vendor 
    \slim 

也許我應該設置\ slim \ src \ settings.php

因爲它表明修身應用程序錯誤:

Type: RuntimeException Message: Callable App\controllers\HomeController does not exist File: D:\htdocs\slim\vendor\slim\slim\Slim\CallableResolver.php Line: 90

最後,我也參考這些文章: https://www.slimframework.com/docs/objects/router.html#container-resolution

PHP修身框架創建控制器 PHP Slim Framework Create Controller

我怎麼能上創建中間件Slim Framework 3? How can i create middleware on Slim Framework 3?

回答

0

你忘了定義命名空間上的HomeController文件,加入這一行的HomeController.php頂部:

namespace App\controllers\HomeController; 
相關問題