php - How to pass variables from one page to another in Symfony2 -


I have a login page, when it is logged, gives a welcome page with the user's name on it Use this code to pass the variable $ user on the Welcome page:

  returns $ $ -> ('LoginLoginBundle: Default: welcome.html.twig', array (' User '= & gt; $ user));  

I now have a manager on the welcome page, which has a link to manager.html.twig.

This is the welcome link code page:

  & lt; Li & gt; & Lt; A href = "{{path ('login_login_manager page')}}" Manager & lt; / A & gt; & Lt; / Li & gt;  

The link goes this route:

  login_login_manager Page: Path: / Manager page default: {_controller: LoginLoginBundle: Default: manager}  

The action that indicates the manager:

  Public function manager action (request $ request) {$ session = $ this- & gt; GetRequest () - & gt; GetSession (); $ Em = $ this- & gt; GetDoctrine () - & gt; GetEntityManager (); $ Repository = $ em- & gt; GetRepository ('login login bundle: user'); If ($ session-> ('login' is)) {$ login = $ session- & gt; Get ('login'); $ Username = $ login- & gt; GetUsername (); $ Password = $ Login-> GetPassword (); $ User = $ repository- & gt; Searchonline (array ('username' = & gt; $ username, 'password' = & gt; $ password); If ($ user) {return $ -> - ('Login login bundle: default: manager.html.twig', array ('user' = & gt; $ user)); }} $ This- & gt; Return Return ('Login Login Bundle: Default: login.html.twig'); }  

Now I can not get the $ user on the managerpage. How can I pass it properly between pages?

Edit: I have the editing code but now I get this error:

  An attribute ("username") in the login login bundle, tap variable (" ): Default: welcome.html.twig on line 10  

write your security system Instead, I advise you to use your security component of Symphony, which contains all the important things already done, please read this link carefully:

This A. shows starting from how to be user of the database. If you use Symphony's security component, you will be able to log in to user in the following ways:

  Public function index () {$ user = $ this-> Get ('security.context)') - & gt; GetToken () - & gt; GetUser (); }  

The administrator may have this shortcut:

  Public Function Index () {$ user = $ this- & gt; GetUser (); }  

And if you are using a twig then the last in the template:

   

Comments