thinkphp template How to determine whether the session is empty?

Source: Internet
Author: User
Use the IF tag instead of the empty label, because there is an else case.


  
       
   
    
  • 登 录
  • 注 册
  • {$Think.session.user}
  • It is possible to write the above observations.
    But, condition Part I have tried several, why not?
    1)
    Or
    2)
    Or
    3)
    Or
    4)

    What I want to know is: Why not the above four ways?
    If I do not want to use $_session, want to use Think.session.user words, condition part should write?

    Reply content:

    Use the IF tag instead of the empty label, because there is an else case.

    
      
           
       
        
  • 登 录
  • 注 册
  • {$Think.session.user}
  • It is possible to write the above observations.
    But, condition Part I have tried several, why not?
    1)
    Or
    2)
    Or
    3)
    Or
    4)

    What I want to know is: Why not the above four ways?
    If I do not want to use $_session, want to use Think.session.user words, condition part should write?

    Empty also has else to use AH

    You can try this:

    
      
          
       
        
  • {$Think.session.user}
  • 登 录
  • 注 册
  • TP has an empty label to determine if it is null.

    You can judge the presence of the session ("user") in the controller, pass the user parameter to the template in the session, and do not pass the user parameter, in the template, determine whether the $user variable exists.
    As in action

    // TP中,session是默认开启的,通过session("?sessionName")的方式进行判断,session存在就返回true,反之就返回falseif(session("?user")){    $this->assign("user",session("user"));}

    Then judge in the template

    
      
       
        
        已登录的html code
       
        未登录的html
      
       
  • Related Article

    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.