In the Thinkphp template, how does one determine whether the session is empty?

Source: Internet
Author: User
Use the if label instead of the empty label, because there is also the else. {Code. However, I have tried several condition terms. Why not? 1) & amp; lt; ifcondition & quot; Think. session. user & #039; & #039; & quot; & amp; gt; or 2) & amp; lt; if... use the if label instead of the empty label, because there is also the else.


      
   
  • Login
  • Note volume
  • {$ Think. session. user}
  • It is acceptable to test the above.
    However, I have tried several condition terms. Why not?
    1)
    Or
    2)
    Or
    3)
    Or
    4)

    What I want to know is: why can't the above four methods work?
    If I don't want to use $ _ SESSION and want to use Think. session. user, how should I write the condition part?

    Reply content:

    Use the if label instead of the empty label, because there is also the else.

    
          
       
  • Login
  • Note volume
  • {$ Think. session. user}
  • It is acceptable to test the above.
    However, I have tried several condition terms. Why not?
    1)
    Or
    2)
    Or
    3)
    Or
    4)

    What I want to know is: why can't the above four methods work?
    If I don't want to use $ _ SESSION and want to use Think. session. user, how should I write the condition part?

    Empty also has else usage.

    You can try it like this:

    
         
       
  • {$ Think. session. user}
  • Login
  • Note volume
  • Tp has an empty tag to determine whether it is empty.

    You can determine whether the session ("user") exists in the Controller. If the session exists, the user parameter is passed to the template. If the session does not exist, the user parameter is not passed. In the template, determine whether the $ user variable exists.
    For example

    // In TP, the session is enabled by default ("? SessionName "). If a session exists, true is returned. Otherwise, falseif (session ("? User ") {$ this-> assign (" user ", session (" user "));}

    Then judge in the template

    
      
       
    Logged-on html code
       Unlogged html
      

    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.