当前位置:首页 > CMS教程 > Thinkphp > 列表

thinkphp的$this的用法介绍(附代码)

发布:smiling 来源: PHP粉丝网  添加日期:2020-02-04 16:58:19 浏览: 评论:0 

本篇文章给大家带来的内容是关于thinkphp的$this的用法介绍(附代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

常用方法:

$this -> user[''id] 在user表中查询user_info ,user_info的其它字段值可以去对应的主表中查询各种值。

在HomeController.class.php中建立几个方法(获取渠道消息,获取用户消息,获取推广信息等) 并在一开始就调用,在其它php中public function _initialize(){

parent::_initialize();} 引入这些常用的方法产生的array(用户、渠道、推广等),$this -> user[''id] 在user表中查询user_info ,user_info的其它字段值可以去对应的主表中查询各种值。

  1. public function _initialize(){ 
  2.  
  3.        parent::_initialize(); 
  4.  
  5.        if(PHP_SAPI != 'cli' && !IS_MOBILE){ 
  6.  
  7.            // 非手机访问处理逻辑 
  8.  
  9.        } 
  10.  
  11.   
  12.  
  13.        // 获取渠道信息 
  14.  
  15.        $this -> _get_channel(); 
  16.  
  17.   
  18.  
  19.        // 有推广参数则记录推广信息 
  20.  
  21.        $this -> _record_spread(); 
  22.  
  23.   
  24.  
  25.        // 获取代理信息 
  26.  
  27.        $this -> _get_agent(); 
  28.  
  29.   
  30.  
  31.        // 开发调试时快捷模拟登陆任何用户 
  32.  
  33.        if(APP_DEBUG && $_GET['debug_user_id']){ 
  34.  
  35.            session('user', M('user') -> find($_GET['debug_user_id'])); 
  36.  
  37.        } 
  38.  
  39.   
  40.  
  41.        if(!$this -> user && session('?user')){ 
  42.  
  43.            $this -> user = M('user') -> find(session('user.id')); 
  44.  
  45.        } 
  46.  
  47.   
  48.  
  49.        // cookie 自动登录 
  50.  
  51.        if(!$this -> user && cookie('user') && 0){ 
  52.  
  53.            $cookie = cookie('user'); 
  54.  
  55.            $sign = xmd5($cookie['user_id'].$cookie['timestamp']); 
  56.  
  57.            if($sign != $cookie['sign']){ 
  58.  
  59.                cookie('user', null); 
  60.  
  61.                $cookie = null; 
  62.  
  63.            } 
  64.  
  65.   
  66.  
  67.            if($cookie && $cookie['user_id']){ 
  68.  
  69.                $this -> user = M('user') -> find($cookie['user_id']); 
  70.  
  71.            } 
  72.  
  73.        } 
  74.  
  75.   
  76.  
  77.        // 如果是微信则尝试自动登录 
  78.  
  79.        if(!$this -> user && !session('?no_mp') && IS_WECHAT && CONTROLLER_NAME !='Pay'){ 
  80.  
  81.            $this -> user = $this -> _auto_login(); 
  82.  
  83.        }
  84.  
  85. Home\Controller\CommicController Object 
  86.  
  87. ( 
  88.  
  89.     [view:protected] => Think\View Object 
  90.  
  91.         ( 
  92.  
  93.             [tVar:protected] => Array 
  94.  
  95.                 ( 
  96.  
  97.                     [_geetest] => Array 
  98.  
  99.                         ( 
  100.  
  101.                             [appid] => # 
  102.  
  103.                             [private_key] => # 
  104.  
  105.                         ) 
  106.  
  107.   
  108.  
  109.                     [_qcloud] => Array 
  110.  
  111.                         ( 
  112.  
  113.                             [secretid] => ######## 
  114.  
  115.                             [secretkey] => ### 
  116.  
  117.                             [bucket] =>  # 
  118.  
  119.                             [region] => # 
  120.  
  121.                             [domain] =>  
  122.  
  123.                             [corp] => 0 
  124.  
  125.                         ) 
  126.  
  127.   
  128.  
  129.                     [_reward] => Array 
  130.  
  131.                         ( 
  132.  
  133.                             [signs] => 50;60;70;80;90;100;110 
  134.  
  135.                             [reg] => 200 
  136.  
  137.                             [daily_read] => 200 
  138.  
  139.                             [invite] => 200 
  140.  
  141.                             [new_comments] => 100 
  142.  
  143.                             [new_fav] => 100 
  144.  
  145.                             [new_task] => 500 
  146.  
  147.                         ) 
  148.  
  149.   
  150.  
  151.                     [_site] => Array 
  152.  
  153.                         ( 
  154.  
  155.                             [name] => # 
  156.  
  157.                             [ip] => 47.104.197.243 
  158.  
  159.                             [url] => # 
  160.  
  161.                             [cdn_url] =>  
  162.  
  163.                             [channel_dn_tpl] => # 
  164.  
  165.                             [app_url] =>  
  166.  
  167.                             [logo] => ./Public/upload/images/1901/21/6934249.png 
  168.  
  169.                             [open_token] => abcd 
  170.  
  171.                             [stat_code] =>  
  172.  
  173.                             [copyright] => Copyright © #. All Rights Reserved.  
  174.  
  175.                             [admin_verify] => 0 
  176.  
  177.                             [novel_close] => 1 
  178.  
  179.                             [commic_close] => 0 
  180.  
  181.                             [reg] => 1 
  182.  
  183.                             [upload] => local 
  184.  
  185.                             [money] => 0 
  186.  
  187.                             [wxpay] => 1 
  188.  
  189.                             [alipay] => 0 
  190.  
  191.                             [personal_wxpay] => 0 
  192.  
  193.                             [personal_key] =>  
  194.  
  195.                             [abcyzf] => 0 
  196.  
  197.                         ) 
  198.  
  199.   
  200.  
  201.                     [_sms] => Array 
  202.  
  203.                         ( 
  204.  
  205.                             [user] => # 
  206.  
  207.                             [pass] => # 
  208.  
  209.                             [tpl] => #您的验证码为{code},十分钟内有效。 
  210.  
  211.                         ) 
  212.  
  213.   
  214.  
  215.                     [_super] => Array 
  216.  
  217.                         ( 
  218.  
  219.                             [name] => # 
  220.  
  221.                             [pass] => # 
  222.  
  223.                         ) 
  224.  
  225.   
  226.  
  227.                     [_withdraw] => Array 
  228.  
  229.                         ( 
  230.  
  231.                             [request] => 100 
  232.  
  233.                             [day_limit] => 1 
  234.  
  235.                         ) 
  236.  
  237.   
  238.  
  239.                     [_theme] => Array 
  240.  
  241.                         ( 
  242.  
  243.                             [default] => fox 
  244.  
  245.                         ) 
  246.  
  247.   
  248.  
  249.                     [_share] => Array 
  250.  
  251.                         ( 
  252.  
  253.                             [debug] => 0 
  254.  
  255.                             [title] => 51读小说 
  256.  
  257.                             [desc] => 51读小说,比生活更精彩。 
  258.  
  259.                             [pic] => # 
  260.  
  261.                         ) 
  262.  
  263.   
  264.  
  265.                     [_reg] => Array 
  266.  
  267.                         ( 
  268.  
  269.                             [auto] => 0 
  270.  
  271.                             [mobile] => 1 
  272.  
  273.                             [email] => 0 
  274.  
  275.                         ) 
  276.  
  277.   
  278.  
  279.                     [_abcyzf] => Array 
  280.  
  281.                         ( 
  282.  
  283.                             [pid] => 18065 
  284.  
  285.                             [key] => 12niiKRIZ2w9Iz92I71IkwTTl471kzZN 
  286.  
  287.                         ) 
  288.  
  289.   
  290.  
  291.                     [_expense] => Array 
  292.  
  293.                         ( 
  294.  
  295.                             [rate] => 0 
  296.  
  297.                         ) 
  298.  
  299.   
  300.  
  301.                     [_zhaoshang] => Array 
  302.  
  303.                         ( 
  304.  
  305.                             [title] => 11 
  306.  
  307.                             [logo] =>  
  308.  
  309.                             [qrcode] =>  
  310.  
  311.                             [anli1] =>  
  312.  
  313.                             [anli2] =>  
  314.  
  315.                             [anli3] => # 
  316.  
  317.                             [contact] => 11 
  318.  
  319.                             [demo] => 11 
  320.  
  321.                             [copyright] => 11 
  322.  
  323.                         ) 
  324.  
  325.   
  326.  
  327.                     [channel] =>  
  328.  
  329.                     [user] => Array 
  330.  
  331.                         ( 
  332.  
  333.                             [id] => 2328 
  334.  
  335.                             [channel_id] => 0 
  336.  
  337.                             [agent_id] => 0 
  338.  
  339.                             [nickname] => # 
  340.  
  341.                             [sex] => 0 
  342.  
  343.                             [headimg] => ./Public/images/nohead.jpg 
  344.  
  345.                             [create_time] => 1551418049 
  346.  
  347.                             [mobile] => # 
  348.  
  349.                             [email] =>  
  350.  
  351.                             [pass] => # 
  352.  
  353.                             [money] => 0.00 
  354.  
  355.                             [points] => 1980.00 
  356.  
  357.                             [consume] => 0.00 
  358.  
  359.                             [parent] => 0 
  360.  
  361.                             [province] =>  
  362.  
  363.                             [city] =>  
  364.  
  365.                             [vip_time] => 0 
  366.  
  367.                             [last_withdraw] => 0 
  368.  
  369.                             [font_size] => 18 
  370.  
  371.                             [color_style] =>  
  372.  
  373.                             [subscribe] => 0 
  374.  
  375.                             [last_ip] => 127.0.0.1 
  376.  
  377.                             [last_time] => 1552362452 
  378.  
  379.                             [login_times] => 0 
  380.  
  381.                             [last_active] =>  
  382.  
  383.                             [charge_notice] => 0 
  384.  
  385.                             [status] => 0 
  386.  
  387.                         ) 
  388.  
  389.   
  390.  
  391.                     [cur_module] => Commic 
  392.  
  393.                     [mp_qrcode] => https://open.weixin.qq.com/qr/code?username= 
  394.  
  395.                 ) 
  396.  
  397.   
  398.  
  399.             [theme:protected] =>  
  400.  
  401.         ) 
  402.  
  403.  //phpfensi.com 
  404.  
  405.     [config:protected] => Array 
  406.  
  407.         ( 
  408.  
  409.         ) 
  410.  
  411.   
  412.  
  413. )    

Tags: $this的用法介绍

分享到: