当前位置:首页 > 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.     [view:protected] => Think\View Object 
  89.  
  90.         ( 
  91.  
  92.             [tVar:protected] => Array 
  93.  
  94.                 ( 
  95.  
  96.                     [_geetest] => Array 
  97.  
  98.                         ( 
  99.  
  100.                             [appid] => # 
  101.  
  102.                             [private_key] => # 
  103.  
  104.                         ) 
  105.  
  106.   
  107.  
  108.                     [_qcloud] => Array 
  109.  
  110.                         ( 
  111.  
  112.                             [secretid] => ######## 
  113.  
  114.                             [secretkey] => ### 
  115.  
  116.                             [bucket] =>  # 
  117.  
  118.                             [region] => # 
  119.  
  120.                             [domain] =>  
  121.  
  122.                             [corp] => 0 
  123.  
  124.                         ) 
  125.  
  126.   
  127.  
  128.                     [_reward] => Array 
  129.  
  130.                         ( 
  131.  
  132.                             [signs] => 50;60;70;80;90;100;110 
  133.  
  134.                             [reg] => 200 
  135.  
  136.                             [daily_read] => 200 
  137.  
  138.                             [invite] => 200 
  139.  
  140.                             [new_comments] => 100 
  141.  
  142.                             [new_fav] => 100 
  143.  
  144.                             [new_task] => 500 
  145.  
  146.                         ) 
  147.  
  148.   
  149.  
  150.                     [_site] => Array 
  151.  
  152.                         ( 
  153.  
  154.                             [name] => # 
  155.  
  156.                             [ip] => 47.104.197.243 
  157.  
  158.                             [url] => # 
  159.  
  160.                             [cdn_url] =>  
  161.  
  162.                             [channel_dn_tpl] => # 
  163.  
  164.                             [app_url] =>  
  165.  
  166.                             [logo] => ./Public/upload/images/1901/21/6934249.png 
  167.  
  168.                             [open_token] => abcd 
  169.  
  170.                             [stat_code] =>  
  171.  
  172.                             [copyright] => Copyright © #. All Rights Reserved.  
  173.  
  174.                             [admin_verify] => 0 
  175.  
  176.                             [novel_close] => 1 
  177.  
  178.                             [commic_close] => 0 
  179.  
  180.                             [reg] => 1 
  181.  
  182.                             [upload] => local 
  183.  
  184.                             [money] => 0 
  185.  
  186.                             [wxpay] => 1 
  187.  
  188.                             [alipay] => 0 
  189.  
  190.                             [personal_wxpay] => 0 
  191.  
  192.                             [personal_key] =>  
  193.  
  194.                             [abcyzf] => 0 
  195.  
  196.                         ) 
  197.  
  198.   
  199.  
  200.                     [_sms] => Array 
  201.  
  202.                         ( 
  203.  
  204.                             [user] => # 
  205.  
  206.                             [pass] => # 
  207.  
  208.                             [tpl] => #您的验证码为{code},十分钟内有效。 
  209.  
  210.                         ) 
  211.  
  212.   
  213.  
  214.                     [_super] => Array 
  215.  
  216.                         ( 
  217.  
  218.                             [name] => # 
  219.  
  220.                             [pass] => # 
  221.  
  222.                         ) 
  223.  
  224.   
  225.  
  226.                     [_withdraw] => Array 
  227.  
  228.                         ( 
  229.  
  230.                             [request] => 100 
  231.  
  232.                             [day_limit] => 1 
  233.  
  234.                         ) 
  235.  
  236.   
  237.  
  238.                     [_theme] => Array 
  239.  
  240.                         ( 
  241.  
  242.                             [default] => fox 
  243.  
  244.                         ) 
  245.  
  246.   
  247.  
  248.                     [_share] => Array 
  249.  
  250.                         ( 
  251.  
  252.                             [debug] => 0 
  253.  
  254.                             [title] => 51读小说 
  255.  
  256.                             [desc] => 51读小说,比生活更精彩。 
  257.  
  258.                             [pic] => # 
  259.  
  260.                         ) 
  261.  
  262.   
  263.  
  264.                     [_reg] => Array 
  265.  
  266.                         ( 
  267.  
  268.                             [auto] => 0 
  269.  
  270.                             [mobile] => 1 
  271.  
  272.                             [email] => 0 
  273.  
  274.                         ) 
  275.  
  276.   
  277.  
  278.                     [_abcyzf] => Array 
  279.  
  280.                         ( 
  281.  
  282.                             [pid] => 18065 
  283.  
  284.                             [key] => 12niiKRIZ2w9Iz92I71IkwTTl471kzZN 
  285.  
  286.                         ) 
  287.  
  288.   
  289.  
  290.                     [_expense] => Array 
  291.  
  292.                         ( 
  293.  
  294.                             [rate] => 0 
  295.  
  296.                         ) 
  297.  
  298.   
  299.  
  300.                     [_zhaoshang] => Array 
  301.  
  302.                         ( 
  303.  
  304.                             [title] => 11 
  305.  
  306.                             [logo] =>  
  307.  
  308.                             [qrcode] =>  
  309.  
  310.                             [anli1] =>  
  311.  
  312.                             [anli2] =>  
  313.  
  314.                             [anli3] => # 
  315.  
  316.                             [contact] => 11 
  317.  
  318.                             [demo] => 11 
  319.  
  320.                             [copyright] => 11 
  321.  
  322.                         ) 
  323.  
  324.   
  325.  
  326.                     [channel] =>  
  327.  
  328.                     [user] => Array 
  329.  
  330.                         ( 
  331.  
  332.                             [id] => 2328 
  333.  
  334.                             [channel_id] => 0 
  335.  
  336.                             [agent_id] => 0 
  337.  
  338.                             [nickname] => # 
  339.  
  340.                             [sex] => 0 
  341.  
  342.                             [headimg] => ./Public/images/nohead.jpg 
  343.  
  344.                             [create_time] => 1551418049 
  345.  
  346.                             [mobile] => # 
  347.  
  348.                             [email] =>  
  349.  
  350.                             [pass] => # 
  351.  
  352.                             [money] => 0.00 
  353.  
  354.                             [points] => 1980.00 
  355.  
  356.                             [consume] => 0.00 
  357.  
  358.                             [parent] => 0 
  359.  
  360.                             [province] =>  
  361.  
  362.                             [city] =>  
  363.  
  364.                             [vip_time] => 0 
  365.  
  366.                             [last_withdraw] => 0 
  367.  
  368.                             [font_size] => 18 
  369.  
  370.                             [color_style] =>  
  371.  
  372.                             [subscribe] => 0 
  373.  
  374.                             [last_ip] => 127.0.0.1 
  375.  
  376.                             [last_time] => 1552362452 
  377.  
  378.                             [login_times] => 0 
  379.  
  380.                             [last_active] =>  
  381.  
  382.                             [charge_notice] => 0 
  383.  
  384.                             [status] => 0 
  385.  
  386.                         ) 
  387.  
  388.   
  389.  
  390.                     [cur_module] => Commic 
  391.  
  392.                     [mp_qrcode] => https://open.weixin.qq.com/qr/code?username= 
  393.  
  394.                 ) 
  395.  
  396.   
  397.  
  398.             [theme:protected] =>  
  399.  
  400.         ) 
  401.  
  402.  //phpfensi.com 
  403.  
  404.     [config:protected] => Array 
  405.  
  406.         ( 
  407.  
  408.         ) 
  409.  
  410.   
  411.  
  412. )    

Tags: $this的用法介绍

分享到: