好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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

本篇文章给大家带来的内容是关于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的其它字段值可以去对应的主表中查询各种值。

 public function _initialize(){
		parent::_initialize();
		if(PHP_SAPI != 'cli' && !IS_MOBILE){
			// 非手机访问处理逻辑
		}

		// 获取渠道信息
		$this -> _get_channel();

		// 有推广参数则记录推广信息
		$this -> _record_spread();

		// 获取代理信息
		$this -> _get_agent();

		// 开发调试时快捷模拟登陆任何用户
		if(APP_DEBUG && $_GET['debug_user_id']){
			session('user', M('user') -> find($_GET['debug_user_id']));
		}

		if(!$this -> user && session('?user')){
			$this -> user = M('user') -> find(session('user.id'));
		}

		// cookie 自动登录
		if(!$this -> user && cookie('user') && 0){
			$cookie = cookie('user');
			$sign = xmd5($cookie['user_id'].$cookie['timestamp']);
			if($sign != $cookie['sign']){
				cookie('user', null);
				$cookie = null;
			}

			if($cookie && $cookie['user_id']){
				$this -> user = M('user') -> find($cookie['user_id']);
			}
		}

		// 如果是微信则尝试自动登录
		if(!$this -> user && !session('?no_mp') && IS_WECHAT && CONTROLLER_NAME !='Pay'){
			$this -> user = $this -> _auto_login();
		}
Home\Controller\CommicController Object
(
    [view:protected] =&gt; Think\View Object
   (
  [tVar:protected] =&gt; Array
 (
[_geetest] =&gt; Array
    (
   [appid] =&gt; #
   [private_key] =&gt; #
    )

[_qcloud] =&gt; Array
    (
   [secretid] =&gt; ########
   [secretkey] =&gt; ###
   [bucket] =&gt;  #
   [region] =&gt; #
   [domain] =&gt; 
   [corp] =&gt; 0
    )

[_reward] =&gt; Array
    (
   [signs] =&gt; 50;60;70;80;90;100;110
   [reg] =&gt; 200
   [daily_read] =&gt; 200
   [invite] =&gt; 200
   [new_comments] =&gt; 100
   [new_fav] =&gt; 100
   [new_task] =&gt; 500
    )

[_site] =&gt; Array
    (
   [name] =&gt; #
   [ip] =&gt; 47.104.197.243
   [url] =&gt; #
   [cdn_url] =&gt; 
   [channel_dn_tpl] =&gt; #
   [app_url] =&gt; 
   [logo] =&gt; ./Public/upload/images/1901/21/6934249.png
   [open_token] =&gt; abcd
   [stat_code] =&gt; 
   [copyright] =&gt; Copyright ? #. All Rights Reserved. 
   [admin_verify] =&gt; 0
   [novel_close] =&gt; 1
   [commic_close] =&gt; 0
   [reg] =&gt; 1
   [upload] =&gt; local
   [money] =&gt; 0
   [wxpay] =&gt; 1
   [alipay] =&gt; 0
   [personal_wxpay] =&gt; 0
   [personal_key] =&gt; 
   [abcyzf] =&gt; 0
    )

[_sms] =&gt; Array
    (
   [user] =&gt; #
   [pass] =&gt; #
   [tpl] =&gt; #您的验证码为{code},十分钟内有效。
    )

[_super] =&gt; Array
    (
   [name] =&gt; #
   [pass] =&gt; #
    )

[_withdraw] =&gt; Array
    (
   [request] =&gt; 100
   [day_limit] =&gt; 1
    )

[_theme] =&gt; Array
    (
   [default] =&gt; fox
    )

[_share] =&gt; Array
    (
   [debug] =&gt; 0
   [title] =&gt; 51读小说
   [desc] =&gt; 51读小说,比生活更精彩。
   [pic] =&gt; #
    )

[_reg] =&gt; Array
    (
   [auto] =&gt; 0
   [mobile] =&gt; 1
   [email] =&gt; 0
    )

[_abcyzf] =&gt; Array
    (
   [pid] =&gt; 18065
   [key] =&gt; 12niiKRIZ2w9Iz92I71IkwTTl471kzZN
    )

[_expense] =&gt; Array
    (
   [rate] =&gt; 0
    )

[_zhaoshang] =&gt; Array
    (
   [title] =&gt; 11
   [logo] =&gt; 
   [qrcode] =&gt; 
   [anli1] =&gt; 
   [anli2] =&gt; 
   [anli3] =&gt; #
   [contact] =&gt; 11
   [demo] =&gt; 11
   [copyright] =&gt; 11
    )

[channel] =&gt; 
[user] =&gt; Array
    (
   [id] =&gt; 2328
   [channel_id] =&gt; 0
   [agent_id] =&gt; 0
   [nickname] =&gt; #
   [sex] =&gt; 0
   [headimg] =&gt; ./Public/images/nohead.jpg
   [create_time] =&gt; 1551418049
   [mobile] =&gt; #
   [email] =&gt; 
   [pass] =&gt; #
   [money] =&gt; 0.00
   [points] =&gt; 1980.00
   [consume] =&gt; 0.00
   [parent] =&gt; 0
   [province] =&gt; 
   [city] =&gt; 
   [vip_time] =&gt; 0
   [last_withdraw] =&gt; 0
   [font_size] =&gt; 18
   [color_style] =&gt; 
   [subscribe] =&gt; 0
   [last_ip] =&gt; 127.0.0.1
   [last_time] =&gt; 1552362452
   [login_times] =&gt; 0
   [last_active] =&gt; 
   [charge_notice] =&gt; 0
   [status] =&gt; 0
    )

[cur_module] =&gt; Commic
[mp_qrcode] =&gt; https://open.weixin.qq测试数据/qr/code?username=
 )

  [theme:protected] =&gt; 
   )

    [config:protected] =&gt; Array
   (
   )

)	

以上就是thinkphp的$this的用法介绍(附代码)的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于thinkphp的$this的用法介绍(附代码)的详细内容...

  阅读:48次