{"id":28,"date":"2016-04-01T09:10:06","date_gmt":"2016-04-01T09:10:06","guid":{"rendered":"http:\/\/120.27.50.22\/wordpress\/?p=28"},"modified":"2016-04-08T09:50:19","modified_gmt":"2016-04-08T09:50:19","slug":"kohana-bootstrap","status":"publish","type":"post","link":"http:\/\/www.homconnect.cn\/?p=28","title":{"rendered":"kohana\u5f15\u5bfc"},"content":{"rendered":"<h2>Bootstrap<\/h2>\n<p>bootstrap\u7684\u4f4d\u7f6e\u5728application\/bootstrap.php\u3002\u5b83\u8d1f\u8d23\u5efa\u7acbKohana\u7684\u73af\u5883\u548c\u6267\u884c\u7684\u4e3b\u54cd\u5e94\u3002\u5b83\u662f\u88abindex.php\u5305\u542b\u8fdb\u53bb\u7684\u3002<\/p>\n<h2>\n\u5efa\u7acb\u73af\u5883<\/h2>\n<p>bootstrap\u9996\u5148\u8bbe\u7f6e\u65f6\u533a\u548c\u8bed\u8a00\u73af\u5883\uff0c\u7136\u540e\u589e\u52a0Kohana\u7684autoloader\u4f7f\u7ea7\u8054\u6587\u4ef6\u7cfb\u7edf\u5de5\u4f5c\u3002\u4f60\u53ef\u4ee5\u5728\u8fd9\u91cc\u6dfb\u52a0\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u7684\u6240\u6709\u8bbe\u7f6e\u3002<\/p>\n<p><em>\/\/ Sample excerpt from bootstrap.php with comments trimmed down<\/em><\/p>\n<p><em>\/\/ Set the default time zone.<\/em><br \/>\n<em>date_default_timezone_set(&#8216;America\/Chicago&#8217;);<\/em><\/p>\n<p><em>\/\/ Set the default locale.<\/em><br \/>\n<em>setlocale(LC_ALL, &#8216;en_US.utf-8&#8217;);<\/em><\/p>\n<p><em>\/\/ Enable the Kohana auto-loader.<\/em><br \/>\n<em>spl_autoload_register(array(&#8216;Kohana&#8217;, &#8216;auto_load&#8217;));<\/em><\/p>\n<p><em>\/\/ Enable the Kohana auto-loader for unserialization.<\/em><br \/>\n<em>ini_set(&#8216;unserialize_callback_func&#8217;, &#8216;spl_autoload_call&#8217;);<\/em><\/p>\n<h2>\nInitialization and Configuration\uff08\u521d\u59cb\u5316\u548c\u914d\u7f6e\uff09<\/h2>\n<p>kohana\u8c03\u7528Kohana::init\u6765\u521d\u59cb\u5316\uff0c\u5e76\u542f\u7528\u65e5\u5fd7\u548c\u914d\u7f6e\u8bfb\u5199\u5668\u3002<\/p>\n<p>\/\/ Sample excerpt from bootstrap.php with comments trimmed down<\/p>\n<p><em>Kohana::init(array(&#8216;<\/em><br \/>\n<em> base_url&#8217; =&gt; &#8216;\/kohana\/&#8217;,<\/em><br \/>\n<em> index_file =&gt; false,<\/em><br \/>\n<em>));<\/em><\/p>\n<p><em>\/\/ Attach the file writer to logging. Multiple writers are supported.<\/em><br \/>\n<em>Kohana::$log-&gt;attach(new Kohana_Log_File(APPPATH.&#8217;logs&#8217;));<\/em><\/p>\n<p><em>\/\/ Attach a file reader to config. Multiple readers are supported.<\/em><br \/>\n<em>Kohana::$config-&gt;attach(new Kohana_Config_File);<\/em><\/p>\n<p>\u60a8\u53ef\u4ee5\u6dfb\u52a0\u6761\u4ef6\u8bed\u53e5\uff0c\u4f7f\u5f15\u5bfc\u5177\u6709\u57fa\u4e8e\u67d0\u4e9b\u8bbe\u7f6e\u4e0d\u540c\u7684\u503c\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53d1\u73b0\u65e0\u8bba\u662f\u73b0\u573a\u68c0\u67e5$_ SERVER[&#8216;HTTP_HOST&#8217;]\uff0c\u5e76\u8bbe\u7f6e\u7f13\u5b58\uff0c\u5206\u6790\uff0c\u7b49\u7b49\u3002\u56e0\u6b64\u3002\u8fd9\u4ec5\u4ec5\u662f\u4e00\u4e2a\u4f8b\u5b50\uff0c\u4e5f\u6709\u8bb8\u591a\u4e0d\u540c\u7684\u65b9\u5f0f\u6765\u5b8c\u6210\u540c\u6837\u7684\u4e8b\u60c5\u3002<br \/>\n<em>\/\/ Excerpt from http:\/\/github.com\/isaiahdw\/kohanaphp.com\/blob\/f2afe8e28b\/application\/bootstrap.php<\/em><br \/>\n<em>&#8230; [trimmed]<\/em><\/p>\n<p><em>\/**<\/em><br \/>\n<em> * Set the environment status by the domain.<\/em><br \/>\n<em> *\/<\/em><br \/>\n<em>if (strpos($_SERVER[&#8216;HTTP_HOST&#8217;], &#8216;kohanaframework.org&#8217;) !== FALSE)<\/em><br \/>\n<em>{<\/em><br \/>\n<em> \/\/ We are live!<\/em><br \/>\n<em> Kohana::$environment = Kohana::PRODUCTION;<\/em><\/p>\n<p><em> \/\/ Turn off notices and strict errors<\/em><br \/>\n<em> error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT);<\/em><br \/>\n<em>}<\/em><\/p>\n<p><em>\/**<\/em><br \/>\n<em> * Initialize Kohana, setting the default options.<\/em><br \/>\n<em> &#8230; [trimmed]<\/em><br \/>\n<em> *\/<\/em><br \/>\n<em>Kohana::init(array(<\/em><br \/>\n<em> &#8216;base_url&#8217; =&gt; Kohana::$environment === Kohana::PRODUCTION ? &#8216;\/&#8217; : &#8216;\/kohanaframework.org\/&#8217;,<\/em><br \/>\n<em> &#8216;caching&#8217; =&gt; Kohana::$environment === Kohana::PRODUCTION,<\/em><br \/>\n<em> &#8216;profile&#8217; =&gt; Kohana::$environment !== Kohana::PRODUCTION,<\/em><br \/>\n<em> &#8216;index_file&#8217; =&gt; FALSE,<\/em><br \/>\n<em>));<\/em><\/p>\n<p><em>&#8230; [trimmed]<\/em><\/p>\n<h2>\nModules\uff08\u6a21\u5757\uff09<\/h2>\n<p>\u6a21\u5757\u4f7f\u7528Kohana::modules()\u52a0\u8f7d\u8fdb\u6765\u7684\u3002\u5305\u542b\u6a21\u5757\u662f\u53ef\u9009\u7684\u3002\u9635\u5217\u4e2d\u7684\u6bcf\u4e2a\u952e\u5e94\u8be5\u662f\u6a21\u5757\u7684\u540d\u79f0\uff0c\u5e76\u4e14\u8be5\u503c\u662f\u6240\u8ff0\u8def\u5f84\u6a21\u5757\uff0c\u76f8\u5bf9\u6216\u7edd\u5bf9\u7684\u3002<\/p>\n<p><em>\/\/ Example excerpt from bootstrap.php<\/em><\/p>\n<p><em>Kohana::modules(array(<\/em><br \/>\n<em> &#8216;database&#8217; =&gt; MODPATH.&#8217;database&#8217;,<\/em><br \/>\n<em> &#8216;orm&#8217; =&gt; MODPATH.&#8217;orm&#8217;,<\/em><br \/>\n<em> &#8216;userguide&#8217; =&gt; MODPATH.&#8217;userguide&#8217;,<\/em><br \/>\n<em>));<\/em><\/p>\n<h2>\nRoutes\uff08\u8def\u7531\uff09<\/h2>\n<p>\u8def\u7531\u662f\u7531Route::set() \u5b9a\u4e49\u7684<\/p>\n<p><em>\/\/ The default route that comes with Kohana 3<\/em><br \/>\n<em>Route::set(&#8216;default&#8217;, &#8216;(&lt;controller&gt;(\/&lt;action&gt;(\/&lt;id&gt;)))&#8217;)<\/em><br \/>\n<em> -&gt;defaults(array(<\/em><br \/>\n<em> &#8216;controller&#8217; =&gt; &#8216;Welcome&#8217;,<\/em><br \/>\n<em> &#8216;action&#8217; =&gt; &#8216;index&#8217;,<\/em><br \/>\n<em> ));<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bootstrap bootstrap\u7684\u4f4d\u7f6e\u5728application\/bootstrap.php\u3002\u5b83\u8d1f\u8d23\u5efa\u7acbK &hellip; <a href=\"http:\/\/www.homconnect.cn\/?p=28\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201ckohana\u5f15\u5bfc\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[17,7],"_links":{"self":[{"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/posts\/28"}],"collection":[{"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=28"}],"version-history":[{"count":1,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/posts\/28\/revisions"}],"predecessor-version":[{"id":29,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/posts\/28\/revisions\/29"}],"wp:attachment":[{"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}