本篇文章给大家带来的内容是关于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] => Think\View Object ( [tVar:protected] => Array ( [_geetest] => Array ( [appid] => # [private_key] => # ) [_qcloud] => Array ( [secretid] => ######## [secretkey] => ### [bucket] => # [region] => # [domain] => [corp] => 0 ) [_reward] => Array ( [signs] => 50;60;70;80;90;100;110 [reg] => 200 [daily_read] => 200 [invite] => 200 [new_comments] => 100 [new_fav] => 100 [new_task] => 500 ) [_site] => Array ( [name] => # [ip] => 47.104.197.243 [url] => # [cdn_url] => [channel_dn_tpl] => # [app_url] => [logo] => ./Public/upload/images/1901/21/6934249.png [open_token] => abcd [stat_code] => [copyright] => Copyright © #. All Rights Reserved. [admin_verify] => 0 [novel_close] => 1 [commic_close] => 0 [reg] => 1 [upload] => local [money] => 0 [wxpay] => 1 [alipay] => 0 [personal_wxpay] => 0 [personal_key] => [abcyzf] => 0 ) [_sms] => Array ( [user] => # [pass] => # [tpl] => #您的验证码为{code},十分钟内有效。 ) [_super] => Array ( [name] => # [pass] => # ) [_withdraw] => Array ( [request] => 100 [day_limit] => 1 ) [_theme] => Array ( [default] => fox ) [_share] => Array ( [debug] => 0 [title] => 51读小说 [desc] => 51读小说,比生活更精彩。 [pic] => # ) [_reg] => Array ( [auto] => 0 [mobile] => 1 [email] => 0 ) [_abcyzf] => Array ( [pid] => 18065 [key] => 12niiKRIZ2w9Iz92I71IkwTTl471kzZN ) [_expense] => Array ( [rate] => 0 ) [_zhaoshang] => Array ( [title] => 11 [logo] => [qrcode] => [anli1] => [anli2] => [anli3] => # [contact] => 11 [demo] => 11 [copyright] => 11 ) [channel] => [user] => Array ( [id] => 2328 [channel_id] => 0 [agent_id] => 0 [nickname] => # [sex] => 0 [headimg] => ./Public/images/nohead.jpg [create_time] => 1551418049 [mobile] => # [email] => [pass] => # [money] => 0.00 [points] => 1980.00 [consume] => 0.00 [parent] => 0 [province] => [city] => [vip_time] => 0 [last_withdraw] => 0 [font_size] => 18 [color_style] => [subscribe] => 0 [last_ip] => 127.0.0.1 [last_time] => 1552362452 [login_times] => 0 [last_active] => [charge_notice] => 0 [status] => 0 ) [cur_module] => Commic [mp_qrcode] => https://open.weixin.qq.com/qr/code?username= ) [theme:protected] => ) [config:protected] => Array ( ) )
以上是thinkphp的$this的用法介紹(附程式碼)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

tomakephpapplicationsfaster,關注台詞:1)useopcodeCachingLikeLikeLikeLikeLikePachetoStorePreciledScompiledScriptbyTecode.2)MinimimiedAtabaseSqueriSegrieSqueriSegeriSybysequeryCachingandeffeftExting.3)Leveragephp7 leveragephp7 leveragephp7 leveragephpphp7功能forbettercodeefficy.4)

到ImprovephPapplicationspeed,關注台詞:1)啟用opcodeCachingwithapCutoredUcescriptexecutiontime.2)實現databasequerycachingingusingpdotominiminimizedatabasehits.3)usehttp/2tomultiplexrequlexrequestsandreduceconnection.4 limitesclection.4.4

依赖注入(DI)通过显式传递依赖关系,显著提升了PHP代码的可测试性。1)DI解耦类与具体实现,使测试和维护更灵活。2)三种类型中,构造函数注入明确表达依赖,保持状态一致。3)使用DI容器管理复杂依赖,提升代码质量和开发效率。

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

phpisusedforsenderemailsduetoitsbuilt-inmail()函數andsupportivelibrariesLikePhpMailerAndSwiftMailer.1)usethemail()functionForbasiceMails,butithasimails.2)butithasimail.2)

PHP性能瓶颈可以通过以下步骤解决:1)使用Xdebug或Blackfire进行性能分析,找出问题所在;2)优化数据库查询并使用缓存,如APCu;3)使用array_filter等高效函数优化数组操作;4)配置OPcache进行字节码缓存;5)优化前端,如减少HTTP请求和优化图片;6)持续监控和优化性能。通过这些方法,可以显著提升PHP应用的性能。

依賴性注射(DI)InphpisadesignPatternthatManages和ReducesClassDeptions,增強量強制性,可驗證性和MATIALWINABIOS.ItallowSpasspassingDepentenciesLikEdenciesLikedAbaseConnectionStoclasseconnectionStoclasseSasasasasareTers,interitationAseTestingEaseTestingEaseTestingEaseTestingEasingAndScalability。

cachingimprovesphpermenceByStorcyResultSofComputationsorqucrouctationsorquctationsorquickretrieval,reducingServerLoadAndenHancingResponsetimes.feftectivestrategiesinclude:1)opcodecaching,whereStoresCompiledSinmememorytssinmemorytoskipcompliation; 2)datacaching datacachingsingMemccachingmcachingmcachings


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

Atom編輯器mac版下載
最受歡迎的的開源編輯器

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

Dreamweaver CS6
視覺化網頁開發工具

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中