0

After enabling the php engine by editing the config/packages/framework.yaml, I am now facing the "The template ::/test/test.html.php" does not exit" error !!

Controller :

namespace App\Controller;

use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class TestController extends Controller
    {
    /**
    * @Route("/test.html.php", name="testphp")
    */
    public function testphp(){
        return $this->render('test/test.html.php');
    }
}

Path: Templates/test/test.html.php

4
  • 1
    Can we see your file tree? Commented Jul 16, 2018 at 11:13
  • 3
    And are you sure it's not test/test.html.twig Commented Jul 16, 2018 at 11:14
  • As a side note: your route does not have to have the extension (or even the same name for that matter!). You can simply have * @Route("/test", name="testphp") Commented Jul 16, 2018 at 11:26
  • Thanks for your comment guys ! Commented Aug 1, 2018 at 10:50

2 Answers 2

5

I figured it out. The Symfony team has not yet updated the php templating engine, so it looks for files not in the templates folder, but in src/Resources/views/. If you were to put your file in src\Resources\views\test\test.html.php everything works (I tested it).

Sign up to request clarification or add additional context in comments.

4 Comments

You're welcome. I would also look into using Twig because it seems like the whole php templating is something that is no longer desired in Symfony 4. See the related github issue I created: github.com/symfony/symfony/issues/27964
Thanks for your cool advice but after making the changes that resovled the first problem, I adjusted the path for the require_once to fit the new Resources/view location of the requiring file and now I am having another critical problem, ` The autoloader expected class "App\Resources\views\test\config" to be defined in file "/home/user1645/projects/application_symfony/vendor/composer/../../src/R esources/views/test/test.config". The file was found but the class was not in it, the class name or namespace probably has a typo. `
I am not sure what you mean with "I adjusted the path for the require_once". I think it is best to just create a new question with your code so I (and others) can have a look what might be the issue.
I somehow solved the problem yesterday , again, thanks for your help.
0

run composer require symfony/twig-bundle you will get a template folder with base.html.twig file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.