1
class DefaultController extends Controller
{
    public function indexAction($page, $name) {
        return $this->render('default/new.html.php'
        //         , array(
        //     $name => 'bob'
        // )
        );
    }
}

new.html.php

<p>Welcome to the index <?= $name; ?></p> 

When I use this code it is returning an error message.

But,

<p>Welcome to the index {{ name }}

this returns me correct output.

I want to use .html.php instead of .html.twig

I am going through this https://symfony.com/doc/3.4/templating/PHP.html

routing.yml

app:
    path:      /dd
    defaults:
        _controller: AppBundle:Default:index
        page:        1
        name:       "bob"

config.yml

framework:
    # ...
    templating:
        engines: ['twig', 'php']

Note: I am using ubuntu16.04 and Symfony 3.4

20
  • What is error message? Commented Nov 29, 2018 at 5:14
  • Controller "AppBundle\Controller\DefaultController::indexAction()" requires that you provide a value for the "$name" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one. Commented Nov 29, 2018 at 5:16
  • You pass parameter to action, but you didn't define it in route. symfony.com/doc/3.4/routing/extra_information.html Commented Nov 29, 2018 at 5:20
  • Now I get the output but "name" is still not displayed - my output is "Welcome to the index" Commented Nov 29, 2018 at 5:30
  • 1
    @newbie stackoverflow.com/questions/21279901/… maybe short php tags are not supported? Commented Nov 29, 2018 at 9:13

1 Answer 1

1

Tried locally according to Symfony documentation:

/**
 * @Route("/test", name="test_route")
 */
public function test()
{
    return $this->render(
        'test.html.php',
        [
            'test_var' => 'Hello test',
        ]
    );
}

My test.html.php:

<?php
echo $test_var;

This outputs Hello test.

PS: Tried get_defined_vars();, the variable should be seen there.

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

7 Comments

Tried ...still blank output...will it be an issue in php server in ubuntu??
It could be configuration issue. What does var_dump(get_defined_vars()); outputs?
maybe the problem will be with my configuration...will check it..problem seems to be in php..because php content is not accepted in new.html.php still, that page returns a blank output.. if I write something out of php tag then it is displayed in new.html.php
I tried it in windows too..but no change...do I want to change anything in routing.yml
Are you using annotations to route? If so - no.
|

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.