Render view through the controller using Slim Framework 3

3

I'm trying to find a way to render the view using a controller in slim framework but for some reason I'm getting the error:

Message: Using $this when not in object context

The function is a public function and is inside a class normally and I'm following what it says in Documentation < a>

My route:

$app->get('/home', '\App\Http\Controller\Teste::main');

The Base Controller:

class Controller
{
   protected $ci;

   public function __construct(ContainerInterface $ci)
   {
       $this->ci = $ci;
   }
}

The test class:

class Teste extends Controller
{
   public function index($request, $response)
   {
      return "Hello!"; // Funciona
   }

   public function main($request, $response)
   {
       var_dump($this->ci); // Apresenta o erro
   }
}
    
asked by anonymous 24.12.2016 / 21:20

1 answer

2
___ erkimt ___ Render view through the controller using Slim Framework 3 ______ qstntxt ___

I'm trying to find a way to render the view using a controller in %code% but for some reason I'm getting the error:

$app->get('/home', '\App\Http\Controller\Teste::main');

The function is a public function and is inside a class normally and I'm following what it says in Documentation < a>

My route:

$app->get('/home', '\App\Http\Controller\Teste:main');

The Base Controller:

$app->get('/home', '\App\Http\Controller\Teste::main');

The test class:

$app->get('/home', '\App\Http\Controller\Teste:main');
    
______ ___ azszpr173421

I've missed many hours with an error similar to this one. The problem is this:

%pre%

By using "::" you are calling a static method. And for this reason, this does not exist. Try this:

%pre%     
___
25.12.2016 / 00:48