4

I am new to symfony and I want to use PHP templating engine. Below are the steps I followed to make it work.

1.Enabled PHP templating engine in config.yml

templating:
    engines: ['twig', 'php']

2.Defined my controller path and defaults in routing.yml

hello:
    path:      /hello/{name}
    defaults:  { _controller: AppBundle:Hello:index, name:World }

3.Created HelloController.php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class HelloController extends Controller
{
    public function indexAction($name)
    {
        return $this->render('hello/name.html.php', array(
            'name'=>$name
        ));
    }
}

4.Created a view \app\Resources\views\Hello\name.html.php

<!-- app/Resources/views/Hello/name.html.php -->
Hello <?php echo $name ?>!

but when I try to access http://127.0.0.1:8000/hello, it shows me below error

The template "hello/name.html.php" does not exist.

500 Internal Server Error - InvalidArgumentException

I changed template folder name from 'Hello' to 'hello' but still same error. Also tried to render template like this

return $this->render(
    'AppBundle:Hello:index.html.php',
    array('name' => $name)
);

but no luck, I must be missing something here. Can someone please guide me to right direction?

Note: hello/name.html.twig is loading without any error

Thank you!

2
  • symfony.com/doc/current/cookbook/templating/PHP.html this page says that you need to use annotation: /** * @Template(engine="php") */ Did you try to use it? Commented Sep 23, 2015 at 11:25
  • folder name should be hello and clear the cache after that change. Commented Sep 23, 2015 at 11:28

1 Answer 1

3

If your template is in app/Resources/views/Hello/ folder, you should use this notation:

$response = $this->render(':Hello:name.html.php');

If you would move it to src/AppBundle/Resources/views/Hello folder, then use

$response = $this->render('AppBundle:Hello:name.html.php');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.