Slim 4 slim / twig render impossible

Good morning all

after a lot of search on the forum and google
and the doc of slim v4 impossible to display my templates I would like your light big thank you. (even if the subject has already been mentioned)

Container.php

09

frontController.php
26

error

Hi @djo, welcome! :wave:

The simple answer is that you’re trying to call the render() method on $this->view, but if you notice you haven’t defined it in your constructor. You have two choices:

  1. Add a private $view; property at the top of your class and in your constructor add $this->view = $container->get('view'); (working from memory, but I think that’s right)
  2. Or, in your homePage() method, change $this->view->render() to $this->container->get('view')->render()

There’s a bigger piece where we don’t recommend that you inject the entire container, preferring to inject the dependencies themselves, but you appear to be using larger controllers, rather than dedicated action classes, so that will be a bit laborious. Also, if you’re using a container that supports auto-wiring (it looks like you’re using PHPDI, which does), you won’t get the best from it this way.

This is for another topic, though :slight_smile:

I hope that helps.

1 Like

hello Antee
thanks for your help really
and I take note for the container
I started on slim but thanks for the advice