I have the following error:
Fatal error: Using $ this when not in object context in C: \ Users \ PC \ Desktop \ slim_framework \ app \ Controllers \ HomeController.php online 10
composer.json
{
"require": {
"slim/slim": "^3.9",
"slim/php-view": "^2.2"
},
"autoload": {
"psr-4":{
"App\": "app"
}
}
}
index.php
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require 'vendor/autoload.php';
require 'config/config.php';
$app = new \Slim\App(['settings' => $config]);
$container = $app->getContainer();
$container['view'] = new \Slim\Views\PhpRenderer("resources/views/");
require 'app/routes.php';
$app->run();
routes.php
<?php
$app->get('/', 'App\Controllers\HomeController::index');
Controller.php
<?php
namespace App\Controllers;
class Controller {
protected $container;
public function __construct(\Slim\Container $container){
$this->container = $container;
}
public function __get($propriedade){
if($this->container->{$propriedade}){
return $this->container->{$propriedade};
}
}
}
HomeController
<?php
namespace App\Controllers;
use App\Controllers\Controller;
class HomeController extends Controller{
public function index($request, $response){
$response = $this->view->render($response, 'template.phtml');
return $response;
}
}
I'm using php 5.4