Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony2 / FOSUserBundle: Change render variables in response without altering parent class
    text
    copied!<p>One of my classes currently extends the BaseController on the FOSUserBundle, and returns the parent action. However, due to project spec, I shouldn't have the need to edit the parent class. Is there a way of sending additional variables, for twig to render, through the child response?</p> <p><strong>Child Class:</strong></p> <pre><code>class ChangePasswordController extends BaseController { public function changePasswordAction(Request $request) { $response = parent::changePasswordAction($request); return $response; // and 'myVariable' =&gt; $myVariable } } </code></pre> <p><strong>Parent Class:</strong></p> <pre><code>class ChangePasswordController extends ContainerAware { /** * Change user password */ public function changePasswordAction(Request $request) { //lots of code..... return $this-&gt;container-&gt;get('templating') -&gt;renderResponse( 'FOSUserBundle:ChangePassword:changePassword.html.' .$this-&gt;container-&gt;getParameter('fos_user.template.engine'), array( 'form' =&gt; $form-&gt;createView() //and 'myVariable' =&gt; $myVariable ) ); } } </code></pre> <p>So to summarise, is there a way of passing something to the parent class, without changing the parent class... whilst rendering the twig view with an additional variable.</p> <h1>-- Update --</h1> <p>Essentially I want to render a form using the FOSUserBundle changePassword action, therefore this works fine:</p> <pre><code>return $this-&gt;container -&gt;get('templating') -&gt;renderResponse( 'FOSUserBundle:ChangePassword:changePassword.html.'.$this-&gt;container-&gt;getParameter('fos_user.template.engine'), array('form' =&gt; $form-&gt;createView()) ); </code></pre> <p>However, I want to pass more variables to the view, just like the 'form' is passed as shown above, <em>without</em> altering the <strong>FosUserBundle ChangePassword Controller</strong>. Therefore I have a class which inherits the that controller, adds some additional functionality and returns the parent change password action:</p> <pre><code>class ChangePassController extends ChangePasswordController { public function changePasswordAction(Request $request) { // more code...... $response = parent::changePasswordAction($request); return $response; } } </code></pre> <p>But, like with most applications, I want to add more than just the form variable to a view template. So is there a way of passing an additional variable to the view, without altering the parent controller / action? Like (but not like) pushing 'myVariable' => $myVariable to the parent changePasswordAction return statement?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload