How does thinkphp pass values between different functions of different Action classes?

Source: Internet
Author: User
How does thinkphp pass values between different functions of different Action classes? I use ThinkPHP to log on to the page. log on to the page and submit the form to action = & quot ;__ APP _/Index/login_do & quot;. then, I wrote the login_do function in the IndexAction class: how does publi thinkphp pass values between different functions of different Action classes?
I used ThinkPHP to log on to the page.
On the login page, submit the form to action = "_ APP _/Index/login_do". then, I wrote the login_do function in the IndexAction class:
Public function login_do ()
{
If ($ _ SESSION ['verify ']! = Md5 ($ _ POST ['userauthcode'])
{
$ This-> error ('verification code error! ');
}
$ Username = $ _ POST ['username'];
$ Password = $ _ POST ['password'];
$ Password = md5 ($ password );

$ User = M ('user ');
$ Res = $ user-> where ("user_name = '$ username' & password =' $ password'")-> find ();
If ($ res)
{
Redirect ('../Home/home', 1, "logon successful! The page is Redirecting ...");
}
Else
{
$ This-> error ('logon failed! ');
}
}




The following is the HomeAction class:
Class HomeAction extends Action
{
Public function home ()
{
$ This-> display ();
}
}




.../Tpl/Home/home.html is the Home page.





Now the question is: I want to display the user name on the Main Page. how can I transfer the user name value to home.html? hope you can teach me with a high finger and give me a prompt. thank you!

------ Solution --------------------
Store the session during login and use $ name = Session: get ('name') in the home controller to get the user name.

Then $ this-> assign ('name', $ name );
The final output template is on the template page {$ name}

Speed score
------ Solution --------------------
Follow the description of #1 and implement it in the corresponding _ URL _/top method.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.