0
votes

I am using symfony 3.2.4 (got with console --version). I am working the openclassroom tutorial. That controller always return the error below. Nevertheless, the file below exist with and is accessible.

src/OC/PlatformBundle/Resources/views/Advert/index.html.twig

I got crazy with that. Does someone have an idea ?

Thanks in advance.

<?php
// src/OC/PlatformBundle/Controller/AdvertController.php
namespace OC\PlatformBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class AdvertController extends Controller
{
  public function indexAction()
  {
    $content = $this->get('templating')->render('OCPlatformBundle:Advert:index.html.twig');

    return new Response($content);
  }
}

Unable to find template "OCPlatformBundle:Advert:index.html.twig" (looked into: /var/www/html/symfony/app/Resources/views, /var/www/html/symfony/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form).

*

1
It is almost like your bundle was not registered in AppKernel, but that would not make sense, wouldn't it?Jovan Perovic
And don't forget to clean the cache! (twig have to be compiled to php by symfony and putted in cache)goto
yeah the bubdle is registered and the controller is working, while it return a string response and not a render content. I clean the cache via the console (this was well done because i had to replace the 777 right on the /var/dev folder) but this change nothing.... :/totofgo

1 Answers

0
votes

Did you try to create your template in app/Resources/views/Advert/index.html.twig ?

This is a better practice : Store all your application's templates in app/Resources/views/ directory. (From SF doc)...

So, you'll be able to "call" it by this way:

/***/
public function indexAction()
{
    return $this->render('Advert/index.html.twig', []);
}
/***/