0

0

我把ci的 loader函数改了下 大神帮我看看?

php中文网

php中文网

发布时间:2016-07-25 08:47:56

|

1073人浏览过

|

来源于php中文网

原创

  1. protected function _ci_load($_ci_data) {
  2. // Set the default data variables
  3. foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val) {
  4. $$_ci_val = (!isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val];
  5. }
  6. $file_exists = FALSE;
  7. $_ci_ext = '.html';
  8. // Set the path to the requested file
  9. if ($_ci_path != '') {
  10. $_ci_x = explode('/', $_ci_path);
  11. $_ci_file = end($_ci_x) . $_ci_ext;
  12. } else {
  13. //可以注释掉下面这一行,因为我们已经可以通过路由来自动加载视图
  14. //$_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);//获取视图文件的后缀名,默认是不传递后缀名的
  15. //拼接视图路径
  16. //加载配置,以方便获取mca(m:模块,c:控制器,a:action)的值
  17. $this->config = &load_class('Config', 'core');
  18. $directory_trigger = $this->config->item('directory_trigger');
  19. $controller_trigger = $this->config->item('controller_trigger');
  20. $function_trigger = $this->config->item('function_trigger');
  21. //用户没有配置伪静态的情况下,使用pathinfo
  22. $urlinfo = explode('/', $_SERVER['REQUEST_URI']);
  23. $urlinfo['module'] = @$urlinfo[1] ? $urlinfo[1] : 'home';
  24. $urlinfo['controller'] = @$urlinfo[2] ? $urlinfo[2] : 'index';
  25. $urlinfo['action'] = @$urlinfo[3] ? $urlinfo[3] : 'index';
  26. $m = isset($_GET[$directory_trigger]) && $_GET[$directory_trigger]!='' ? $_GET[$directory_trigger] : $urlinfo['module'];
  27. $c =isset($_GET[$controller_trigger]) && $_GET[$controller_trigger]!='' ? $_GET[$controller_trigger] : $urlinfo['controller'];
  28. $a = isset($_GET[$function_trigger]) && $_GET[$function_trigger] !=''? $_GET[$function_trigger] : $urlinfo['action'];
  29. //特殊处理common/header(包含公共头部/底部)的情况
  30. $slasharr = explode('/', $_ci_view);
  31. if (count($slasharr) > 1) {
  32. $_ci_file = $m . '/' . $slasharr['0'].'/' .$slasharr['1'] . $_ci_ext;
  33. } else {
  34. //默认的视图名称(不包含后缀名)
  35. $view_name = $_ci_view == '' ? $a : $_ci_view; //如果没有传视图的名称,默认使用action的名称
  36. $_ci_file = $m . '/' . $c . '/' . $view_name . $_ci_ext;
  37. }
  38. foreach ($this->_ci_view_paths as $view_file => $cascade) {
  39. if (file_exists($view_file . $_ci_file)) {
  40. $_ci_path = $view_file . $_ci_file;
  41. $file_exists = TRUE;
  42. break;
  43. }
  44. if (!$cascade) {
  45. break;
  46. }
  47. }
  48. }
  49. if (!$file_exists && !file_exists($_ci_path)) {
  50. show_error('Unable to load the requested file: ' . $_ci_file);
  51. }
  52. // This allows anything loaded using $this->load (views, files, etc.)
  53. // to become accessible from within the Controller and Model functions.
  54. $_ci_CI = & get_instance();
  55. foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var) {
  56. if (!isset($this->$_ci_key)) {
  57. $this->$_ci_key = & $_ci_CI->$_ci_key;
  58. }
  59. }
  60. /*
  61. * Extract and cache variables
  62. *
  63. * You can either set variables using the dedicated $this->load_vars()
  64. * function or via the second parameter of this function. We'll merge
  65. * the two types and cache them so that views that are embedded within
  66. * other views can have access to these variables.
  67. */
  68. if (is_array($_ci_vars)) {
  69. $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
  70. }
  71. extract($this->_ci_cached_vars);
  72. /*
  73. * Buffer the output
  74. *
  75. * We buffer the output for two reasons:
  76. * 1. Speed. You get a significant speed boost.
  77. * 2. So that the final rendered template can be
  78. * post-processed by the output class. Why do we
  79. * need post processing? For one thing, in order to
  80. * show the elapsed page load time. Unless we
  81. * can intercept the content right before it's sent to
  82. * the browser and then stop the timer it won't be accurate.
  83. */
  84. ob_start();
  85. // If the PHP installation does not support short tags we'll
  86. // do a little string replacement, changing the short tags
  87. // to standard PHP echo statements.
  88. if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE) {
  89. echo eval('?>' . preg_replace("/;*\s*\?>/", "; ?>", str_replace('=', '
  90. } else {
  91. include($_ci_path); // include() vs include_once() allows for multiple views with the same name
  92. }
  93. log_message('debug', 'File loaded: ' . $_ci_path);
  94. // Return the file data if requested
  95. if ($_ci_return === TRUE) {
  96. $buffer = ob_get_contents();
  97. @ob_end_clean();
  98. return $buffer;
  99. }
  100. /*
  101. * Flush the buffer... or buff the flusher?
  102. *
  103. * In order to permit views to be nested within
  104. * other views, we need to flush the content back out whenever
  105. * we are beyond the first level of output buffering so that
  106. * it can be seen and included properly by the first included
  107. * template and any subsequent ones. Oy!
  108. *
  109. */
  110. if (ob_get_level() > $this->_ci_ob_level + 1) {
  111. ob_end_flush();
  112. } else {
  113. $_ci_CI->output->append_output(ob_get_contents());
  114. @ob_end_clean();
  115. }
  116. }
复制代码


热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

通义千问
通义千问

阿里巴巴推出的全能AI助手

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
pixiv网页版官网登录与阅读指南_pixiv官网直达入口与在线访问方法
pixiv网页版官网登录与阅读指南_pixiv官网直达入口与在线访问方法

本专题系统整理pixiv网页版官网入口及登录访问方式,涵盖官网登录页面直达路径、在线阅读入口及快速进入方法说明,帮助用户高效找到pixiv官方网站,实现便捷、安全的网页端浏览与账号登录体验。

928

2026.02.13

微博网页版主页入口与登录指南_官方网页端快速访问方法
微博网页版主页入口与登录指南_官方网页端快速访问方法

本专题系统整理微博网页版官方入口及网页端登录方式,涵盖首页直达地址、账号登录流程与常见访问问题说明,帮助用户快速找到微博官网主页,实现便捷、安全的网页端登录与内容浏览体验。

307

2026.02.13

Flutter跨平台开发与状态管理实战
Flutter跨平台开发与状态管理实战

本专题围绕Flutter框架展开,系统讲解跨平台UI构建原理与状态管理方案。内容涵盖Widget生命周期、路由管理、Provider与Bloc状态管理模式、网络请求封装及性能优化技巧。通过实战项目演示,帮助开发者构建流畅、可维护的跨平台移动应用。

183

2026.02.13

TypeScript工程化开发与Vite构建优化实践
TypeScript工程化开发与Vite构建优化实践

本专题面向前端开发者,深入讲解 TypeScript 类型系统与大型项目结构设计方法,并结合 Vite 构建工具优化前端工程化流程。内容包括模块化设计、类型声明管理、代码分割、热更新原理以及构建性能调优。通过完整项目示例,帮助开发者提升代码可维护性与开发效率。

29

2026.02.13

Redis高可用架构与分布式缓存实战
Redis高可用架构与分布式缓存实战

本专题围绕 Redis 在高并发系统中的应用展开,系统讲解主从复制、哨兵机制、Cluster 集群模式及数据分片原理。内容涵盖缓存穿透与雪崩解决方案、分布式锁实现、热点数据优化及持久化策略。通过真实业务场景演示,帮助开发者构建高可用、可扩展的分布式缓存系统。

103

2026.02.13

c语言 数据类型
c语言 数据类型

本专题整合了c语言数据类型相关内容,阅读专题下面的文章了解更多详细内容。

54

2026.02.12

雨课堂网页版登录入口与使用指南_官方在线教学平台访问方法
雨课堂网页版登录入口与使用指南_官方在线教学平台访问方法

本专题系统整理雨课堂网页版官方入口及在线登录方式,涵盖账号登录流程、官方直连入口及平台访问方法说明,帮助师生用户快速进入雨课堂在线教学平台,实现便捷、高效的课程学习与教学管理体验。

17

2026.02.12

豆包AI网页版入口与智能创作指南_官方在线写作与图片生成使用方法
豆包AI网页版入口与智能创作指南_官方在线写作与图片生成使用方法

本专题汇总豆包AI官方网页版入口及在线使用方式,涵盖智能写作工具、图片生成体验入口和官网登录方法,帮助用户快速直达豆包AI平台,高效完成文本创作与AI生图任务,实现便捷智能创作体验。

764

2026.02.12

PostgreSQL性能优化与索引调优实战
PostgreSQL性能优化与索引调优实战

本专题面向后端开发与数据库工程师,深入讲解 PostgreSQL 查询优化原理与索引机制。内容包括执行计划分析、常见索引类型对比、慢查询优化策略、事务隔离级别以及高并发场景下的性能调优技巧。通过实战案例解析,帮助开发者提升数据库响应速度与系统稳定性。

92

2026.02.12

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号