Slim Class Controller not found

Asked

Viewed 327 times

1

I’m trying to make a model in MVC here, using some controllers.

Follow my directories:

  • Root/
    • app/
      • Controller/
        • Padrao.php
    • public/
    • index php.
    • Composer.json

My file index php. (Yes, leaving td mixed, after q is running separate in Routes.php, etc):

<?php
require 'vendor/autoload.php';

$app = new \Slim\App([
    'settings' => [
        'displayErrorDetails' => true
    ]
]);

$container = $app->getContainer();

$container['view'] = function ($container) {
    $view = new \Slim\Views\Twig('app/view/', [
        'cache' => false
    ]);

    $basePath = rtrim(str_ireplace('index.php', '', $container['request']->getUri()->getBasePath()), '/');
    $view->addExtension(new Slim\Views\TwigExtension($container['router'], $basePath));

    return $view;
};

$container[App\Controller\Padrao::class] = function ($c) {
    return new App\Controller\Padrao($c->get('view'));
};


/* ============
   Rotas da aplicação
   ============ */

$app->get('/test', App\Controller\Padrao::class);

$app->get('/', function ($req, $res) {
    return $this->view->render($res, 'inicio.twig');
});

$app->run();

My Class (Padrao.php):

<?php

namespace App\Controller;
use Slim\Views\Twig;
use Slim\Router;

final class Padrao {
{
    private $view;
    private $logger;
    public function __construct(Twig $view, LoggerInterface $logger)
    {
        $this->view = $view;
        $this->logger = $logger;
    }
    public function __invoke(Request $request, Response $response, $args)
    {
        $this->logger->info("Home page action dispatched");

        $this->view->render($response, 'home.twig');
        return $response;
    }
}

My Komposer.json:

"autoload": {
        "psr-4": {
            "App\\": "app/"
        }
    }

The problem: When I run, and try to access /test url, it gives the following error:

Class 'App Controller Standard' not found

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.