A solution to transfer variables between thinkphp methods

Source: Internet
Author: User
Passing variables between thinkphp methods
First use object-oriented often this is the case that two methods need to be used in the same way that I read some data from the database in a method to the template and then I find that another method in the same module needs to use this data or one of the variables I don't know what to do. Ask for the big wet to speak Clear Point Ha younger brother rookie
------Solution--------------------
You can define public methods in comment/comment.php, which can be called anywhere.
------Solution--------------------
First write an action that commonaction inherits thinkphp, the code is as follows:
Commonaction extends action{}

Then you inherit the commonaction with all the normal actions, so that the common method is written in Commonaction, and then the common method is called in different child action.
------Solution--------------------
Write it again in the way you need it.
Note that the normal execution of the display method means that the program is finished
Different methods in the same controller are not executed in the same HTTP session, so they are all independent. It's just that you wrote it together.

If other methods need to be called before the display method is executed, the called method uses the same data set as the caller
Then you can put the data set in the Init 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.