{"id":963,"date":"2019-08-15T13:54:18","date_gmt":"2019-08-15T05:54:18","guid":{"rendered":"https:\/\/wyxxt.org.cn\/?p=963"},"modified":"2023-12-04T16:42:22","modified_gmt":"2023-12-04T08:42:22","slug":"%e6%a1%86%e6%9e%b6%e5%85%a5%e5%8f%a3%e6%96%87%e4%bb%b6index-php","status":"publish","type":"post","link":"https:\/\/wyxxt.org.cn\/?p=963","title":{"rendered":"Codeigniter(1)\u2014\u2014\u6846\u67b6\u5165\u53e3\u6587\u4ef6index.php"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/7d195a743bbe1017b6362bad56e9bbff.png\" alt=\"\" \/><\/p>\n<ol>\n<li>index.php \u6587\u4ef6\u4f5c\u4e3a\u524d\u7aef\u63a7\u5236\u5668\uff0c\u521d\u59cb\u5316\u8fd0\u884c CodeIgniter \u6240\u9700\u7684\u57fa\u672c\u8d44\u6e90\uff1b<\/li>\n<li>Router \u68c0\u67e5 HTTP \u8bf7\u6c42\uff0c\u4ee5\u786e\u5b9a\u5982\u4f55\u5904\u7406\u8be5\u8bf7\u6c42\uff1b<\/li>\n<li>\u5982\u679c\u5b58\u5728\u7f13\u5b58\u6587\u4ef6\uff0c\u5c06\u76f4\u63a5\u8f93\u51fa\u5230\u6d4f\u89c8\u5668\uff0c\u4e0d\u7528\u8d70\u4e0b\u9762\u6b63\u5e38\u7684\u7cfb\u7edf\u6d41\u7a0b\uff1b<\/li>\n<li>\u5728\u52a0\u8f7d\u5e94\u7528\u7a0b\u5e8f\u63a7\u5236\u5668\u4e4b\u524d\uff0c\u5bf9 HTTP \u8bf7\u6c42\u4ee5\u53ca\u4efb\u4f55\u7528\u6237\u63d0\u4ea4\u7684\u6570\u636e\u8fdb\u884c\u5b89\u5168\u68c0\u67e5\uff1b<\/li>\n<li>\u63a7\u5236\u5668\u52a0\u8f7d\u6a21\u578b\u3001\u6838\u5fc3\u7c7b\u5e93\u3001\u8f85\u52a9\u51fd\u6570\u4ee5\u53ca\u5176\u4ed6\u6240\u6709\u5904\u7406\u8bf7\u6c42\u6240\u9700\u7684\u8d44\u6e90\uff1b<\/li>\n<li>\u6700\u540e\u4e00\u6b65\uff0c\u6e32\u67d3\u89c6\u56fe\u5e76\u53d1\u9001\u81f3\u6d4f\u89c8\u5668\uff0c\u5982\u679c\u5f00\u542f\u4e86\u7f13\u5b58\uff0c\u89c6\u56fe\u88ab\u4f1a\u5148\u7f13\u5b58\u8d77\u6765\u7528\u4e8e \u540e\u7eed\u7684\u8bf7\u6c42\u3002<\/li>\n<\/ol>\n<h3>1.\u8bbe\u7f6e\u5e94\u7528\u8fd0\u884c\u73af\u5883\u5e38\u91cf<\/h3>\n<pre><code class=\"language-php line-numbers\">    define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');\n<\/code><\/pre>\n<h3>2.\u8bbe\u7f6e\u62a5\u9519\u7ea7\u522b<\/h3>\n<pre><code class=\"language-php line-numbers\">switch (ENVIRONMENT)\n{\n    case 'development':\n        error_reporting(-1);\n        ini_set('display_errors', 1);\n    break;\n\n    case 'testing':\n    case 'production':\n        ini_set('display_errors', 0);\n        if (version_compare(PHP_VERSION, '5.3', '&gt;='))\n        {\n            error_reporting(E_ALL &amp; ~E_NOTICE &amp; ~E_DEPRECATED &amp; ~E_STRICT &amp; ~E_USER_NOTICE &amp; ~E_USER_DEPRECATED);\n        }\n        else\n        {\n            error_reporting(E_ALL &amp; ~E_NOTICE &amp; ~E_STRICT &amp; ~E_USER_NOTICE);\n        }\n    break;\n\n    default:\n        header('HTTP\/1.1 503 Service Unavailable.', TRUE, 503);\n        echo 'The application environment is not set correctly.';\n        exit(1); \/\/ EXIT_ERROR\n}\n<\/code><\/pre>\n<h3>3.\u8bbe\u7f6e\u7cfb\u7edf\u76ee\u5f55\u5e38\u91cf<\/h3>\n<pre><code class=\"language-php line-numbers\">    $system_path = 'system';\n\n    if (defined('STDIN'))\n    {\n        chdir(dirname(__FILE__));\n    }\n\n    if (($_temp = realpath($system_path)) !== FALSE)\n    {\n        $system_path = $_temp.DIRECTORY_SEPARATOR;\n    }\n    else\n    {\n\n        \/\/ Ensure there's a trailing slash\n        $system_path = strtr(\n            rtrim($system_path, '\/\\\\'),\n            '\/\\\\',\n            DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR\n        ).DIRECTORY_SEPARATOR;\n    }\n\n    \/\/ Is the system path correct?\n    if ( ! is_dir($system_path))\n    {\n        header('HTTP\/1.1 503 Service Unavailable.', TRUE, 503);\n        echo 'Your system folder path does not appear to be set correctly. Please open the following file and correct this: '.pathinfo(__FILE__, PATHINFO_BASENAME);\n        exit(3); \/\/ EXIT_CONFIG\n    }\n\n    \/\/ The name of THIS file\n    define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));\n\n    \/\/ Path to the system directory\n    define('BASEPATH', $system_path);\n\n    \/\/ Path to the front controller (this file) directory\n    define('FCPATH', dirname(__FILE__).DIRECTORY_SEPARATOR);\n\n    \/\/ Name of the \"system\" directory\n    define('SYSDIR', basename(BASEPATH));\n<\/code><\/pre>\n<h3>4.\u8bbe\u7f6e\u5e94\u7528\u5e38\u91cf\u76ee\u5f55<\/h3>\n<pre><code class=\"language-php line-numbers\">    $application_folder = 'application';\n\n\n    \/\/ The path to the \"application\" directory\n    if (is_dir($application_folder))\n    {\n        if (($_temp = realpath($application_folder)) !== FALSE)\n        {\n            $application_folder = $_temp;\n        }\n        else\n        {\n            $application_folder = strtr(\n                rtrim($application_folder, '\/\\\\'),\n                '\/\\\\',\n                DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR\n            );\n        }\n    }\n    elseif (is_dir(BASEPATH.$application_folder.DIRECTORY_SEPARATOR))\n    {\n        $application_folder = BASEPATH.strtr(\n            trim($application_folder, '\/\\\\'),\n            '\/\\\\',\n            DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR\n        );\n    }\n    else\n    {\n        header('HTTP\/1.1 503 Service Unavailable.', TRUE, 503);\n        echo 'Your application folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF;\n        exit(3); \/\/ EXIT_CONFIG\n    }\n\n    define('APPPATH', $application_folder.DIRECTORY_SEPARATOR);\n<\/code><\/pre>\n<h3>5.\u8bbe\u7f6e\u89c6\u56fe\u8def\u5f84\u5e38\u91cf<\/h3>\n<pre><code class=\"language-php line-numbers\">    $view_folder = '';\n\n    \/\/ The path to the \"views\" directory\n    if ( ! isset($view_folder[0]) &amp;&amp; is_dir(APPPATH.'views'.DIRECTORY_SEPARATOR))\n    {\n        $view_folder = APPPATH.'views';\n    }\n    elseif (is_dir($view_folder))\n    {\n        if (($_temp = realpath($view_folder)) !== FALSE)\n        {\n            $view_folder = $_temp;\n        }\n        else\n        {\n            $view_folder = strtr(\n                rtrim($view_folder, '\/\\\\'),\n                '\/\\\\',\n                DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR\n            );\n        }\n    }\n    elseif (is_dir(APPPATH.$view_folder.DIRECTORY_SEPARATOR))\n    {\n        $view_folder = APPPATH.strtr(\n            trim($view_folder, '\/\\\\'),\n            '\/\\\\',\n            DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR\n        );\n    }\n    else\n    {\n        header('HTTP\/1.1 503 Service Unavailable.', TRUE, 503);\n        echo 'Your view folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF;\n        exit(3); \/\/ EXIT_CONFIG\n    }\n\n    define('VIEWPATH', $view_folder.DIRECTORY_SEPARATOR);\n<\/code><\/pre>\n<h3>5.\u52a0\u8f7d\u6838\u5fc3\u63a7\u5236\u6587\u4ef6<\/h3>\n<pre><code class=\"language-php line-numbers\"><br \/>\/*\n * --------------------------------------------------------------------\n * LOAD THE BOOTSTRAP FILE\n * --------------------------------------------------------------------\n *\n * And away we go...\n *\/\nrequire_once BASEPATH.'core\/CodeIgniter.php';\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>index.php \u6587\u4ef6\u4f5c\u4e3a\u524d\u7aef\u63a7\u5236\u5668\uff0c\u521d\u59cb\u5316\u8fd0\u884c CodeIgniter \u6240\u9700\u7684\u57fa\u672c\u8d44\u6e90\uff1b Router \u68c0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[15],"tags":[405],"class_list":["post-963","post","type-post","status-publish","format-standard","hentry","category-15","tag-php"],"_links":{"self":[{"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/963","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=963"}],"version-history":[{"count":4,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/963\/revisions"}],"predecessor-version":[{"id":967,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/963\/revisions\/967"}],"wp:attachment":[{"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}