本文实例讲述了php中钩子(hook)的原理与简单应用。分享给大家供大家参考,具体如下:
我们先来回顾下原本的开发流程;
产品汪搞出了一堆需求;
当用户注册成功后需要发送短信、发送邮件等等;
然后聪明机智勇敢的程序猿们就一扑而上;
把这些需求转换成代码扔在 用户注册成功 和 跳转到首页 之间;
没有什么能够阻挡;充满创造力的猿们;
<"htmlcode"><"htmlcode"><"htmlcode"><"简易后台管理<hr>"; // 插件管理 foreach ($pluginList as $k => $v) { // 获取配置项 $config=include './plugin/'.$v.'/config.php'; $word=$config['status']==1 "./index.php" rel="external nofollow" >'.$word.'</a><br />'; } echo '<hr>'; // 输出插件内容 foreach ($pluginList as $k => $v) { // 获取配置项 $config=include './plugin/'.$v.'/config.php'; if ($config['status']==1) { include './plugin/'.$v.'/index.php'; // 运行插件 Hook::run($v); } } // 前往网站首页 } } // 插件类 class Hook{ // 注册添加插件 public static function add($name,$func){ $GLOBALS['hookList'][$name][]=$func; } // 执行插件 public static function run($name,$params=null){ foreach ($GLOBALS['hookList'][$name] as $k => $v) { call_user_func($v,$params); } } } // 更改插件状态 if (isset($_GET['change'])) { // 获取到配置项 $config=include './plugin/plugin'.substr($_GET['change'],-1).'/config.php'; // 如果是开启 那就关闭 如果是关闭 则开启 $config['status']=$config['status']==1 "<".var_export($config,true).';'; file_put_contents('./plugin/'.$_GET['change'].'/config.php', $str); header('Location:./'); } $test=new Test(); $test->index();插件配置项代码:
<"_blank" href="//www.jb51.net/Special/43.htm">php面向对象程序设计入门教程》、《PHP数组(Array)操作技巧大全》、《PHP基本语法入门教程》、《PHP运算与运算符用法总结》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》希望本文所述对大家PHP程序设计有所帮助。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 纯音入心系列纯音乐《天籁古筝》1CD[MP3][331MB]
- 男女对唱典藏天碟《发烧对唱·那个季节里的歌DSD》10CD[WAV]
- 群星2010-歌林精选辑[歌林][WAV+CUE]
- TrioZimbalist-PianoTriosofWeinberg,Auerbach,Dvorak(2024)[24-44,1]wav
- 群星.1992-滚石第一流台湾歌·12王牌大车拼【滚石】【WAV+CUE】
- 林子祥.1984-创作歌集【华纳】【WAV+CUE】
- 周汤豪.2010-周汤豪【华纳】【FLAC分轨】
- Mozart-TheStringQuintets-AmadeusQuartet,CecilAronowitz(2017)[24-44,1][WAV+CUE]
- JamesWilliamsDennisIrwin-Focus(2024,Red)[24-48]FLAC
- 藤泽麻衣《空みあげて》[WAV]
- 纯音入心系列纯音乐《中国古筝经典名曲》1CD[MP3][1.3GB]
- 纯音入心系列纯音乐《古筝新奏:岁月静好与筝语,细水流年与筝同》1CD[MP3][846.9MB]
- 670《脆弱敏感小女生》[320K/MP3][27.53MB]
- 曾琳.2011-好好爱我【南方】【WAV+CUE】
- 范晓萱.1995-RAIN【福茂】【WAV+CUE】