{"id":161,"date":"2018-03-01T14:25:47","date_gmt":"2018-03-01T06:25:47","guid":{"rendered":"https:\/\/wyxxt.org.cn\/?p=161"},"modified":"2023-12-04T17:12:07","modified_gmt":"2023-12-04T09:12:07","slug":"%e6%a1%86%e6%9e%b6%e5%9f%ba%e6%9c%ac%e5%8e%9f%e7%90%86%ef%bc%88%e4%b8%89%ef%bc%89%e8%b7%af%e7%94%b1%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/wyxxt.org.cn\/?p=161","title":{"rendered":"\u6846\u67b6\u57fa\u672c\u539f\u7406\uff08\u4e09\uff09\u8def\u7531\u89e3\u6790"},"content":{"rendered":"<p>index.php<\/p>\n<pre><code class=\"language-php line-numbers\">core\\xxt::run();\/\/\u8fd0\u884c\u6846\u67b6\n<\/code><\/pre>\n<p>core\/xxt.php<\/p>\n<pre><code class=\"language-php line-numbers\">&lt;?php\nnamespace core;\nuse \\core\\lib\\log;\nuse \\core\\lib\\route;\nclass xxt\n{\n    public static $classMap = array();\n    public $assign;\n    static public function run()\n    {\n        log::init();\n        $route = new route();\/\/\uff081\uff09new\u4e00\u4e2aroute\u5bf9\u8c61\uff0c\u8fd0\u884croute\u6784\u9020\u65b9\u6cd5\n        $ctrlClass = $route-&gt;ctrl;\n        $action = $route-&gt;action;\n        $ctrlfile = APP.'\/ctrl\/'.$ctrlClass.'Ctrl.php';\/\/\uff083\uff09\u62fc\u88c5\u63a7\u5236\u5668\u6587\u4ef6\u8def\u5f84        \n        $ctrlClass = '\\\\'.MODULE.'\\ctrl\\\\'.$ctrlClass.'Ctrl';\n        \/\/\uff084\uff09\u62fc\u88c5\u63a7\u5236\u5668\u6587\u4ef6\u7c7b\u540d\n        if(is_file($ctrlfile)) {\n            include $ctrlfile;\n            $ctrl = new $ctrlClass();\n            if(method_exists ($ctrl, $action)) {\n                $ctrl-&gt;$action();\n                log::log('ctrl:'.$ctrlClass.'    '.'action:'.$action);\n            }else{\n                throw new \\Exception('\u627e\u4e0d\u5230\u65b9\u6cd5'.$action);\n            }\n        }else{\n            throw new \\Exception('\u627e\u4e0d\u5230\u63a7\u5236\u5668'.$ctrlClass);\n        }\n    }\n}\n<\/code><\/pre>\n<p>core\/lib\/route.php<\/p>\n<pre><code class=\"language-php line-numbers\">&lt;?php\nnamespace core\\lib;\nclass route\n{\n    public $ctrl;\n    public $action;\n\n    \/**\n     *\u751f\u6210\u5bf9\u8c61\u5c5e\u6027\n     * route constructor.\n     *\/\n    public function __construct()\/\/(2)\u751f\u6210\u5bf9\u8c61\u5c5e\u6027\uff0c\u5bf9\u5e94\u63a7\u5236\u5668\u548c\u65b9\u6cd5\n    {\n        \/\/xxx.com\/index\/index\n        \/\/xxx.com\/index.php\/index\/index\n        \/**\n         * 1\u3001\u9690\u85cfindex.php .htaccess\n         * 2\u3001\u83b7\u53d6URL \u53c2\u6570\u90e8\u5206\n         * 3\u3001\u8fd4\u56de\u5bf9\u5e94\u7684\u63a7\u5236\u5668\u548c\u65b9\u6cd5\n         *\/\n\/\/        p($_SERVER);\n        if(isset($_SERVER['REQUEST_URI']) &amp;&amp; $_SERVER['REQUEST_URI'] != '\/') {\n            $path = $_SERVER['REQUEST_URI'];\n            $patharr = explode('\/',trim($path,'\/'));\n            if(isset($patharr[0])) {\n                $this-&gt;ctrl = $patharr[0];\n            }\n            unset($patharr[0]);\n            if(isset($patharr[1])) {\n                $this-&gt;action = $patharr[1];\n                unset($patharr[1]);\n            }else{\n                $this-&gt;action = conf::get('ACTION','route');\n            }\n            \/\/url\u591a\u4f59\u90e8\u5206\u8f6c\u6362\u6210 GET\n            \/\/id\/1\/str\/2\/test\/3\n            $count = count($patharr) + 2;\n            $i = 2;\n            while($i &lt; $count) {\n                if(isset($patharr[$i + 1])) {\n                    $_GET[$patharr[$i]] = $patharr[$i+1];\n                }\n                $i = $i + 2;\n            }\n\n        }else{\n            $this-&gt;ctrl = conf::get('CTRL','route');\n            $this-&gt;action = conf::get('ACTION','route');\n        }\n\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>index.php core\\xxt::run();\/\/\u8fd0\u884c\u6846\u67b6 core\/xxt.php &lt;?php  [&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-161","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\/161","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=161"}],"version-history":[{"count":14,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/161\/revisions"}],"predecessor-version":[{"id":788,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/161\/revisions\/788"}],"wp:attachment":[{"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}