0
I’m making the following mistake:
Fatal error: Using $this when not in Object context in C: Users PC Desktop slim_framework app Controllers Homecontroller.php on line 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
Vlw for help, now it worked right.
– William