Hi i am new to slim i stuck on this anyone help please
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;
}
}
and 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()
in your container, notnew \App\src\UserController
? – Houle