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!
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With