# MVC architecture for a Slim application

This is more of an entire project review... if this is 'off topic' I apologize. I attempted to make Slim into an mvc structure. I added a few controllers, views and models to allow users to signup, login, make a couple changes to their account, and also allow admins to view the users and change their roles.

Please don't give advice like "this is terrible" but help me take steps to improve it. Also, I know full stack frameworks will do everything for me, but I want to learn myself, so don't refer me to other frameworks or other slim 'skeletons'.

Here is some of the code.

public/index.php:

<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

$settings = require '../src/settings.php';$app = new \Slim\App($settings); ini_set('session.cookie_httponly', 1); ini_set('session.cookie_secure', 1); session_start(); require '../src/dependencies.php'; require '../src/middleware.php'; require '../src/routes.php';$app->run();


src/MyApp/Controller.php:

<?php

namespace MyApp;

class Controller
{
protected $ci; public function __construct($ci) {
$this->ci =$ci;
$this->ci->db;$this->flash = $ci->flash; } public function redirect($route) {
header('Location: ' . $this->ci->router->pathFor($route), true, 302);
die();
}

public function render($response,$view, $args = []) { return$this->ci->view->render($response,$view, $args); } }  src/MyApp/Controller/HomeController.php: <?php namespace MyApp\Controller; use MyApp\Controller; use MyApp\Model\User; class HomeController extends Controller { public function home($request, $response) { return$this->render(\$response, 'index.html.twig');
}
}


What should I do first to improve this? I am concerned with correct use of dependency injection, performance/speed, and general php/mvc best practices. I'm not concerned as much about security holes at this point, but if you see a major problem then go on and help.

Note: This app sometimes gives a twig error when I first run it, but composer remove slim/twig-view and require it again fixes it. Not sure why.