index_example.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <?php
  2. //index.php模板
  3. /**
  4. * CodeIgniter
  5. *
  6. * An open source application development framework for PHP
  7. *
  8. * This content is released under the MIT License (MIT)
  9. *
  10. * Copyright (c) 2014 - 2017, British Columbia Institute of Technology
  11. *
  12. * Permission is hereby granted, free of charge, to any person obtaining a copy
  13. * of this software and associated documentation files (the "Software"), to deal
  14. * in the Software without restriction, including without limitation the rights
  15. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  16. * copies of the Software, and to permit persons to whom the Software is
  17. * furnished to do so, subject to the following conditions:
  18. *
  19. * The above copyright notice and this permission notice shall be included in
  20. * all copies or substantial portions of the Software.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  25. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  26. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  27. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  28. * THE SOFTWARE.
  29. *
  30. * @package CodeIgniter
  31. * @author EllisLab Dev Team
  32. * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
  33. * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
  34. * @license http://opensource.org/licenses/MIT MIT License
  35. * @link https://codeigniter.com
  36. * @since Version 1.0.0
  37. * @filesource
  38. */
  39. /*
  40. *---------------------------------------------------------------
  41. * APPLICATION ENVIRONMENT
  42. *---------------------------------------------------------------
  43. *
  44. * You can load different configurations depending on your
  45. * current environment. Setting the environment also influences
  46. * things like logging and error reporting.
  47. *
  48. * This can be set to anything, but default usage is:
  49. *
  50. * development
  51. * testing
  52. * production
  53. *
  54. * NOTE: If you change these, also change the error_reporting() code below
  55. */
  56. define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'production');
  57. // define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
  58. /*
  59. *---------------------------------------------------------------
  60. * ERROR REPORTING
  61. *---------------------------------------------------------------
  62. *
  63. * Different environments will require different levels of error reporting.
  64. * By default development will show errors but testing and live will hide them.
  65. */
  66. switch (ENVIRONMENT)
  67. {
  68. case 'development':
  69. error_reporting(-1);
  70. ini_set('display_errors', 1);
  71. break;
  72. case 'testing':
  73. case 'production':
  74. ini_set('display_errors', 0);
  75. if (version_compare(PHP_VERSION, '5.3', '>='))
  76. {
  77. error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
  78. }
  79. else
  80. {
  81. error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
  82. }
  83. break;
  84. default:
  85. header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
  86. echo 'The application environment is not set correctly.';
  87. exit(1); // EXIT_ERROR
  88. }
  89. /*
  90. *---------------------------------------------------------------
  91. * SYSTEM DIRECTORY NAME
  92. *---------------------------------------------------------------
  93. *
  94. * This variable must contain the name of your "system" directory.
  95. * Set the path if it is not in the same directory as this file.
  96. */
  97. $system_path = 'system';
  98. /*
  99. *---------------------------------------------------------------
  100. * APPLICATION DIRECTORY NAME
  101. *---------------------------------------------------------------
  102. *
  103. * If you want this front controller to use a different "application"
  104. * directory than the default one you can set its name here. The directory
  105. * can also be renamed or relocated anywhere on your server. If you do,
  106. * use an absolute (full) server path.
  107. * For more info please see the user guide:
  108. *
  109. * https://codeigniter.com/user_guide/general/managing_apps.html
  110. *
  111. * NO TRAILING SLASH!
  112. */
  113. $application_folder = 'application';
  114. /*
  115. *---------------------------------------------------------------
  116. * VIEW DIRECTORY NAME
  117. *---------------------------------------------------------------
  118. *
  119. * If you want to move the view directory out of the application
  120. * directory, set the path to it here. The directory can be renamed
  121. * and relocated anywhere on your server. If blank, it will default
  122. * to the standard location inside your application directory.
  123. * If you do move this, use an absolute (full) server path.
  124. *
  125. * NO TRAILING SLASH!
  126. */
  127. $view_folder = '';
  128. /*
  129. * --------------------------------------------------------------------
  130. * DEFAULT CONTROLLER
  131. * --------------------------------------------------------------------
  132. *
  133. * Normally you will set your default controller in the routes.php file.
  134. * You can, however, force a custom routing by hard-coding a
  135. * specific controller class/function here. For most applications, you
  136. * WILL NOT set your routing here, but it's an option for those
  137. * special instances where you might want to override the standard
  138. * routing in a specific front controller that shares a common CI installation.
  139. *
  140. * IMPORTANT: If you set the routing here, NO OTHER controller will be
  141. * callable. In essence, this preference limits your application to ONE
  142. * specific controller. Leave the function name blank if you need
  143. * to call functions dynamically via the URI.
  144. *
  145. * Un-comment the $routing array below to use this feature
  146. */
  147. // The directory name, relative to the "controllers" directory. Leave blank
  148. // if your controller is not in a sub-directory within the "controllers" one
  149. // $routing['directory'] = '';
  150. // The controller class file name. Example: mycontroller
  151. // $routing['controller'] = '';
  152. // The controller function you wish to be called.
  153. // $routing['function'] = '';
  154. /*
  155. * -------------------------------------------------------------------
  156. * CUSTOM CONFIG VALUES
  157. * -------------------------------------------------------------------
  158. *
  159. * The $assign_to_config array below will be passed dynamically to the
  160. * config class when initialized. This allows you to set custom config
  161. * items or override any default config values found in the config.php file.
  162. * This can be handy as it permits you to share one application between
  163. * multiple front controller files, with each file containing different
  164. * config values.
  165. *
  166. * Un-comment the $assign_to_config array below to use this feature
  167. */
  168. // $assign_to_config['name_of_config_item'] = 'value of config item';
  169. // --------------------------------------------------------------------
  170. // END OF USER CONFIGURABLE SETTINGS. DO NOT EDIT BELOW THIS LINE
  171. // --------------------------------------------------------------------
  172. /*
  173. * ---------------------------------------------------------------
  174. * Resolve the system path for increased reliability
  175. * ---------------------------------------------------------------
  176. */
  177. // Set the current directory correctly for CLI requests
  178. if (defined('STDIN'))
  179. {
  180. chdir(dirname(__FILE__));
  181. }
  182. if (($_temp = realpath($system_path)) !== FALSE)
  183. {
  184. $system_path = $_temp.DIRECTORY_SEPARATOR;
  185. }
  186. else
  187. {
  188. // Ensure there's a trailing slash
  189. $system_path = strtr(
  190. rtrim($system_path, '/\\'),
  191. '/\\',
  192. DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
  193. ).DIRECTORY_SEPARATOR;
  194. }
  195. // Is the system path correct?
  196. if ( ! is_dir($system_path))
  197. {
  198. header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
  199. echo 'Your system folder path does not appear to be set correctly. Please open the following file and correct this: '.pathinfo(__FILE__, PATHINFO_BASENAME);
  200. exit(3); // EXIT_CONFIG
  201. }
  202. /*
  203. * -------------------------------------------------------------------
  204. * Now that we know the path, set the main path constants
  205. * -------------------------------------------------------------------
  206. */
  207. // The name of THIS file
  208. define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
  209. // Path to the system directory
  210. define('BASEPATH', $system_path);
  211. // Path to the system directory
  212. define('__ROOT__', __DIR__);
  213. // Path to the front controller (this file) directory
  214. define('FCPATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
  215. // Name of the "system" directory
  216. define('SYSDIR', basename(BASEPATH));
  217. define('PUBLIC_PATH',dirname(__FILE__).DIRECTORY_SEPARATOR."public");
  218. // The path to the "application" directory
  219. if (is_dir($application_folder))
  220. {
  221. if (($_temp = realpath($application_folder)) !== FALSE)
  222. {
  223. $application_folder = $_temp;
  224. }
  225. else
  226. {
  227. $application_folder = strtr(
  228. rtrim($application_folder, '/\\'),
  229. '/\\',
  230. DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
  231. );
  232. }
  233. }
  234. elseif (is_dir(BASEPATH.$application_folder.DIRECTORY_SEPARATOR))
  235. {
  236. $application_folder = BASEPATH.strtr(
  237. trim($application_folder, '/\\'),
  238. '/\\',
  239. DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
  240. );
  241. }
  242. else
  243. {
  244. header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
  245. echo 'Your application folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF;
  246. exit(3); // EXIT_CONFIG
  247. }
  248. define('APPPATH', $application_folder.DIRECTORY_SEPARATOR);
  249. // The path to the "views" directory
  250. if ( ! isset($view_folder[0]) && is_dir(APPPATH.'views'.DIRECTORY_SEPARATOR))
  251. {
  252. $view_folder = APPPATH.'views';
  253. }
  254. elseif (is_dir($view_folder))
  255. {
  256. if (($_temp = realpath($view_folder)) !== FALSE)
  257. {
  258. $view_folder = $_temp;
  259. }
  260. else
  261. {
  262. $view_folder = strtr(
  263. rtrim($view_folder, '/\\'),
  264. '/\\',
  265. DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
  266. );
  267. }
  268. }
  269. elseif (is_dir(APPPATH.$view_folder.DIRECTORY_SEPARATOR))
  270. {
  271. $view_folder = APPPATH.strtr(
  272. trim($view_folder, '/\\'),
  273. '/\\',
  274. DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
  275. );
  276. }
  277. else
  278. {
  279. header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
  280. echo 'Your view folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF;
  281. exit(3); // EXIT_CONFIG
  282. }
  283. define('VIEWPATH', $view_folder.DIRECTORY_SEPARATOR);
  284. /*
  285. * --------------------------------------------------------------------
  286. * LOAD THE BOOTSTRAP FILE
  287. * --------------------------------------------------------------------
  288. *
  289. * And away we go...
  290. */
  291. require_once './vendor/autoload.php';
  292. require_once BASEPATH.'core/CodeIgniter.php';