How to replace Slim::getInstance() in Slim 3
<p>I am currently trying to follow a Slim tutorial that is utilizing <code>$app = Slim::getInstance();</code> I don't know much about Slim, so the solutions to use a container do not make sense to me. What can I do to make my function provided below actually run?</p>

<pre><code>function jsonResponse($data, $code = 200)
{
    $app = Slim::getInstance();
    $app-&gt;response-&gt;setStatus($code);
    $app-&gt;response-&gt;headers-&gt;set(
    'Content-type',
    'application/json; charset=utf-8'
);
return $app-&gt;response-&gt;setBody(json_encode($data));
}
</code></pre>

<p>I am calling this inside another function for logging in that looks like this:</p>

<pre><code>function login($request) {
$user = json_decode($request-&gt;getBody());
$username = $user-&gt;username;
$password = $user-&gt;password;
if (empty($username) || empty($password)) {
    $error = 'Username and password are required';

    // Bad request
    return jsonResponse($error, 400);
}
$sql = "SELECT first_name, username FROM users "
    . "WHERE username = '$username' AND password = '$password'";
$db = getConnection();
$row = array();
try {
    $result = $db-&gt;query($sql); 
    if (!$result) {
        $error = 'Invalid query: ' . mysql_error();

        // Internal server error
        return jsonResponse($error, 500);
    }
    $user = $result-&gt;fetchAll(PDO::FETCH_OBJ);
    if (empty($user)) {

        // Unauthorized
        return jsonResponse($error, 401);
    }
    $row["user"] = $user;
    $db = null;
} catch(PDOException $e) {
    error_log('{"error":{"text":'. $e-&gt;getMessage() .'}}');
    // $error = array( 'error' =&gt; array ( 'text' =&gt; $e-&gt;getMessage() ) );

    // Internal server error
    return jsonResponse($error, 500);
}

// OK, default is 200
return jsonResponse($row);
}
</code></pre>

<p>My route for the login function is <code>$app-&gt;post('/login_user', 'login');</code></p>

<p>tl;dr I would like an explanation on how to convert older Slim code that uses <code>getInstance()</code>. </p>

<p>Thank you!</p>