I changed the loader function of ci. Can anyone help me?

WBOY
Release: 2016-07-25 08:47:56
Original
918 people have browsed it
  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. //Can be commented out The following line, because we can already automatically load the view through routing
  14. //$_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION); //Get the suffix name of the view file, the default is not to pass the suffix name
  15. //Splice the view path
  16. //Load the configuration to easily obtain the value of mca(m: module, c: controller, 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. //If the user does not configure pseudo-static, use 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. //Special processing common/header (including public Head/Bottom)
  30. $slasharr = explode('/', $_ci_view);
  31. if (count($slasharr) > 1) {
  32. $_ci_file = $m . '/' . $slasharr['0 '].'/' .$slasharr['1'] . $_ci_ext;
  33. } else {
  34. //Default view name (excluding suffix name)
  35. $view_name = $_ci_view == '' ? $a : $_ci_view; //If no view name is passed, the action name is used by default
  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(' } else {
  90. include($_ci_path); // include() vs include_once() allows for multiple views with the same name
  91. }
  92. log_message('debug', 'File loaded: ' . $_ci_path);
  93. // Return the file data if requested
  94. if ($_ci_return === TRUE) {
  95. $buffer = ob_get_contents();
  96. @ob_end_clean();
  97. return $buffer;
  98. }
  99. /*
  100. * Flush the buffer... or buff the flusher?
  101. *
  102. * In order to permit views to be nested within
  103. * other views, we need to flush the content back out whenever
  104. * we are beyond the first level of output buffering so that
  105. * it can be seen and included properly by the first included
  106. * template and any subsequent ones. Oy!
  107. *
  108. */
  109. if (ob_get_level() > $this->_ci_ob_level + 1) {
  110. ob_end_flush();
  111. } else {
  112. $_ci_CI->output->append_output(ob_get_contents());
  113. @ob_end_clean();
  114. }
  115. }
复制代码


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template