kong-zhi-qi.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <!DOCTYPE HTML>
  2. <html lang="" >
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  6. <title>控制器 · GitBook</title>
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  8. <meta name="description" content="">
  9. <meta name="generator" content="GitBook 3.2.3">
  10. <link rel="stylesheet" href="../gitbook/style.css">
  11. <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
  12. <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
  13. <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
  14. <meta name="HandheldFriendly" content="true"/>
  15. <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  16. <meta name="apple-mobile-web-app-capable" content="yes">
  17. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  18. <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
  19. <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
  20. <link rel="next" href="mo-xing.html" />
  21. <link rel="prev" href="lu-you.html" />
  22. </head>
  23. <body>
  24. <div class="book">
  25. <div class="book-summary">
  26. <div id="book-search-input" role="search">
  27. <input type="text" placeholder="Type to search" />
  28. </div>
  29. <nav role="navigation">
  30. <ul class="summary">
  31. <li class="chapter " data-level="1.1" data-path="../">
  32. <a href="../">
  33. 简介
  34. </a>
  35. </li>
  36. <li class="chapter " data-level="1.2" data-path="../chapter1.html">
  37. <a href="../chapter1.html">
  38. 基础用法
  39. </a>
  40. <ul class="articles">
  41. <li class="chapter " data-level="1.2.1" data-path="pei-zhi.html">
  42. <a href="pei-zhi.html">
  43. 配置
  44. </a>
  45. </li>
  46. <li class="chapter " data-level="1.2.2" data-path="lu-you.html">
  47. <a href="lu-you.html">
  48. 路由
  49. </a>
  50. </li>
  51. <li class="chapter active" data-level="1.2.3" data-path="kong-zhi-qi.html">
  52. <a href="kong-zhi-qi.html">
  53. 控制器
  54. </a>
  55. </li>
  56. <li class="chapter " data-level="1.2.4" data-path="mo-xing.html">
  57. <a href="mo-xing.html">
  58. 模型
  59. </a>
  60. </li>
  61. <li class="chapter " data-level="1.2.5" data-path="shi-tu.html">
  62. <a href="shi-tu.html">
  63. 视图
  64. </a>
  65. </li>
  66. </ul>
  67. </li>
  68. <li class="chapter " data-level="1.3" data-path="../qi-ta-bu-chong.html">
  69. <a href="../qi-ta-bu-chong.html">
  70. 其他补充
  71. </a>
  72. <ul class="articles">
  73. <li class="chapter " data-level="1.3.1" data-path="../qi-ta-bu-chong/param.html">
  74. <a href="../qi-ta-bu-chong/param.html">
  75. Param
  76. </a>
  77. </li>
  78. <li class="chapter " data-level="1.3.2" data-path="../qi-ta-bu-chong/tablehelper.html">
  79. <a href="../qi-ta-bu-chong/tablehelper.html">
  80. TableHelper
  81. </a>
  82. </li>
  83. <li class="chapter " data-level="1.3.3" data-path="../qi-ta-bu-chong/ke-zhi-xing-jiao-ben.html">
  84. <a href="../qi-ta-bu-chong/ke-zhi-xing-jiao-ben.html">
  85. 可执行脚本
  86. </a>
  87. </li>
  88. </ul>
  89. </li>
  90. <li class="divider"></li>
  91. <li>
  92. <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
  93. Published with GitBook
  94. </a>
  95. </li>
  96. </ul>
  97. </nav>
  98. </div>
  99. <div class="book-body">
  100. <div class="body-inner">
  101. <div class="book-header" role="navigation">
  102. <!-- Title -->
  103. <h1>
  104. <i class="fa fa-circle-o-notch fa-spin"></i>
  105. <a href=".." >控制器</a>
  106. </h1>
  107. </div>
  108. <div class="page-wrapper" tabindex="-1" role="main">
  109. <div class="page-inner">
  110. <div id="book-search-results">
  111. <div class="search-noresults">
  112. <section class="normal markdown-section">
  113. <h3 id="&#x63A7;&#x5236;&#x5668;">&#x63A7;&#x5236;&#x5668;</h3>
  114. <h6 id="&#x547D;&#x540D;&#x7EA6;&#x5B9A;">&#x547D;&#x540D;&#x7EA6;&#x5B9A;</h6>
  115. <p>&#x7C7B;&#x540D;&#x4F7F;&#x7528;UpperCamelCase&#x98CE;&#x683C;&#xFF0C; <code>XxxController</code>&#xFF0C;Controller&#x7ED3;&#x5C3E;&#xFF0C;&#x6587;&#x4EF6;&#x540D;&#x548C;&#x7C7B;&#x540D;&#x4FDD;&#x6301;&#x4E00;&#x81F4;&#xFF0C;&#x7EE7;&#x627F;<code>BaseController</code>&#x3002;</p>
  116. <p>&#x65B9;&#x6CD5;<code>actionXxx</code>&#xFF0C;action&#x5F00;&#x5934;&#xFF0C;&#x53C2;&#x6570;&#x56FA;&#x5B9A;&#x4E3A;<code>$args</code>&#x63A5;&#x6536;&#x8BF7;&#x6C42;&#x6570;&#x636E;&#xFF08;&#x7B49;&#x6548;&#x4E8E;$REQUEST&#xFF09;&#x3002;</p>
  117. <p>&#x793A;&#x4F8B;:</p>
  118. <pre><code class="lang-php"><span class="hljs-comment">// file: FooController.php</span>
  119. <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">FooController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">BaseController</span> </span>{
  120. <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">actionBar</span><span class="hljs-params">($args)</span> </span>{
  121. <span class="hljs-comment">// code</span>
  122. }
  123. }
  124. </code></pre>
  125. <h6 id="&#x767B;&#x5F55;&#x6001;&#x6821;&#x9A8C;">&#x767B;&#x5F55;&#x6001;&#x6821;&#x9A8C;</h6>
  126. <p>&#x91CD;&#x5199;<code>$loginActions</code>&#x6216;&#x8005;<code>$ajaxLoginActions</code>&#x914D;&#x7F6E;&#xFF0C;&#x533A;&#x522B;&#x5728;&#x4E8E;&#x6821;&#x9A8C;&#x5931;&#x8D25;&#x8FD4;&#x56DE;&#x6570;&#x636E;&#x683C;&#x5F0F;&#x4E0D;&#x4E00;&#x6837;&#x3002;</p>
  127. <p>&#x6821;&#x9A8C;&#x65B9;&#x6CD5;&#x4E3A;<code>User::checkLogin()</code>&#x9879;&#x76EE;&#x5404;&#x81EA;&#x5B9E;&#x73B0;&#x3002;</p>
  128. <p>&#x793A;&#x4F8B;&#xFF1A;</p>
  129. <pre><code class="lang-php"><span class="hljs-keyword">protected</span> $loginActions = [
  130. <span class="hljs-string">&apos;foo&apos;</span>, <span class="hljs-comment">//&#x4E0D;&#x5E26;action&#x524D;&#x7F00;</span>
  131. ];
  132. <span class="hljs-keyword">protected</span> $ajaxLoginAction = [
  133. <span class="hljs-string">&apos;bar&apos;</span>,
  134. ];
  135. </code></pre>
  136. <h6 id="&#x53C2;&#x6570;&#x6821;&#x9A8C;">&#x53C2;&#x6570;&#x6821;&#x9A8C;</h6>
  137. <p>&#x4EFB;&#x4F55;&#x9700;&#x8981;&#x63A5;&#x53D7;&#x53C2;&#x6570;&#x7684;&#x65B9;&#x6CD5;&#x90FD;&#x5E94;&#x8BE5;&#x4F7F;&#x7528;<a href="../qi-ta-bu-chong/param.html"><code>Param</code></a>&#x8FDB;&#x884C;&#x53C2;&#x6570;&#x6821;&#x9A8C;&#x8FC7;&#x6EE4;&#xFF0C;&#x5E38;&#x7528;&#x6821;&#x9A8C;&#x65B9;&#x6CD5;&#x6709;<code>Param::checkParam</code>&#x548C;<code>Param:checkParam2</code>&#x533A;&#x522B;&#x5728;&#x4E8E;<code>Param::checkParam2</code>&#x4F1A;&#x5220;&#x9664;&#x6CA1;&#x5B9A;&#x4E49;&#x6821;&#x9A8C;&#x89C4;&#x5219;&#x7684;&#x53C2;&#x6570;&#x3002;</p>
  138. <p>&#x5B9E;&#x4F8B;:</p>
  139. <pre><code class="lang-php"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">actionFoo</span><span class="hljs-params">($args)</span> </span>{
  140. $rules = [
  141. <span class="hljs-string">&apos;id&apos;</span> =&gt; [<span class="hljs-string">&apos;int&apos;</span>, <span class="hljs-string">&apos;desc&apos;</span> =&gt; <span class="hljs-string">&apos;&#x7528;&#x6237;id&apos;</span>],
  142. ];
  143. Param::checkParam($rules, $args);
  144. }
  145. <span class="hljs-comment">// input: id=123&amp;name=solu</span>
  146. <span class="hljs-comment">// output: $args = [&apos;id&apos; =&gt; 123, &apos;name&apos; =&gt; &apos;solu&apos;];</span>
  147. <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">actionBar</span><span class="hljs-params">($args)</span> </span>{
  148. $rules = [
  149. <span class="hljs-string">&apos;id&apos;</span> =&gt; [<span class="hljs-string">&apos;int&apos;</span>, <span class="hljs-string">&apos;desc&apos;</span> =&gt; <span class="hljs-string">&apos;&#x7528;&#x6237;id&apos;</span>],
  150. ];
  151. Param::checkParam2($rules, $args);
  152. }
  153. <span class="hljs-comment">// input: id=123&amp;name=solu</span>
  154. <span class="hljs-comment">// output: $args = [&apos;id&apos; =&gt; 123];</span>
  155. </code></pre>
  156. <h6 id="&#x63A5;&#x53E3;&#x6587;&#x6863;">&#x63A5;&#x53E3;&#x6587;&#x6863;</h6>
  157. <p>&#x63A5;&#x53E3;&#x6587;&#x6863;&#x662F;&#x901A;&#x8FC7;&#x53CD;&#x5C04;&#x89E3;&#x6790;<code>&#x65B9;&#x6CD5;&#x6CE8;&#x91CA;</code>&#x548C;<code>$rules</code>&#x53C2;&#x6570;&#x6821;&#x9A8C;&#x89C4;&#x5219;&#x81EA;&#x52A8;&#x751F;&#x6210;&#xFF0C;&#x6240;&#x4EE5;&#x8981;&#x6C42;&#x6BCF;&#x4E2A;&#x5BF9;&#x5916;&#x63A5;&#x53E3;&#x90FD;&#x8981;&#x6709;&#x76F8;&#x5E94;&#x6CE8;&#x91CA;&#x3002;&#x5982;&#x679C;&#x4E0D;&#x60F3;&#x63A5;&#x53E3;&#x51FA;&#x73B0;&#x5728;&#x6587;&#x6863;&#x53EF;&#x4EE5;&#x6DFB;&#x52A0;<code>@ignore</code>&#x6CE8;&#x91CA;&#x3002;</p>
  158. <p>&#x793A;&#x4F8B;:</p>
  159. <pre><code class="lang-php"><span class="hljs-comment">/**
  160. * &#x6D4B;&#x8BD5;&#x63A5;&#x53E3;
  161. * <span class="hljs-doctag">@author</span> solu
  162. */</span>
  163. <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">actionFoo</span><span class="hljs-params">($args)</span> </span>{
  164. $rules = [
  165. <span class="hljs-string">&apos;id&apos;</span> =&gt; [<span class="hljs-string">&apos;int&apos;</span>, <span class="hljs-string">&apos;desc&apos;</span> =&gt; <span class="hljs-string">&apos;&#x7528;&#x6237;id&apos;</span>],
  166. ];
  167. Param::checkParam2($rules, $args);
  168. }
  169. </code></pre>
  170. <p>&#x6D4F;&#x89C8;<code>&#x6D4B;&#x8BD5;&#x73AF;&#x5883;</code>//HOST/CONTROLLER/ACTION?doc=class &#x53EF;&#x9884;&#x89C8;&#x6587;&#x6863;&#x3002;</p>
  171. <p><img src="../assets/doc.png" alt=""></p>
  172. </section>
  173. </div>
  174. <div class="search-results">
  175. <div class="has-results">
  176. <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
  177. <ul class="search-results-list"></ul>
  178. </div>
  179. <div class="no-results">
  180. <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
  181. </div>
  182. </div>
  183. </div>
  184. </div>
  185. </div>
  186. </div>
  187. <a href="lu-you.html" class="navigation navigation-prev " aria-label="Previous page: 路由">
  188. <i class="fa fa-angle-left"></i>
  189. </a>
  190. <a href="mo-xing.html" class="navigation navigation-next " aria-label="Next page: 模型">
  191. <i class="fa fa-angle-right"></i>
  192. </a>
  193. </div>
  194. <script>
  195. var gitbook = gitbook || [];
  196. gitbook.push(function() {
  197. gitbook.page.hasChanged({"page":{"title":"控制器","level":"1.2.3","depth":2,"next":{"title":"模型","level":"1.2.4","depth":2,"path":"chapter1/mo-xing.md","ref":"chapter1/mo-xing.md","articles":[]},"previous":{"title":"路由","level":"1.2.2","depth":2,"path":"chapter1/lu-you.md","ref":"chapter1/lu-you.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"chapter1/kong-zhi-qi.md","mtime":"2018-09-08T03:35:56.248Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-09-13T03:13:15.790Z"},"basePath":"..","book":{"language":""}});
  198. });
  199. </script>
  200. </div>
  201. <script src="../gitbook/gitbook.js"></script>
  202. <script src="../gitbook/theme.js"></script>
  203. <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
  204. <script src="../gitbook/gitbook-plugin-search/search.js"></script>
  205. <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
  206. <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
  207. <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
  208. <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
  209. </body>
  210. </html>