 
		 
		{"id":53,"date":"2015-10-02T18:39:27","date_gmt":"2015-10-02T10:39:27","guid":{"rendered":"http:\/\/www.softeng.cn\/?p=53"},"modified":"2015-10-02T19:15:13","modified_gmt":"2015-10-02T11:15:13","slug":"codeigniter%e6%a1%86%e6%9e%b6%e5%85%a5%e9%97%a8%e6%95%99%e7%a8%8b-%e7%ac%ac%e4%ba%8c%e8%af%be-%e5%88%9d%e5%a7%8bmvc","status":"publish","type":"post","link":"https:\/\/www.softeng.cn\/?p=53","title":{"rendered":"CodeIgniter\u6846\u67b6\u5165\u95e8\u6559\u7a0b\u2014\u2014\u7b2c\u4e8c\u8bfe \u521d\u59cbMVC"},"content":{"rendered":"<p><span style=\"font-size: large;\"><strong>\u7b2c\u4e8c\u8bfe \u521d\u59cbMVC<\/strong><\/span><\/p>\n<div align=\"left\"><span style=\"font-family: \u5b8b\u4f53;\">\u4eca\u5929\u7684\u4e3b\u8981\u5185\u5bb9\u662f\uff0c\u4f7f\u7528<\/span>CodeIgniter<span style=\"font-family: \u5b8b\u4f53;\">\u6846\u67b6\u5b8c\u6574\u7684<\/span>MVC<span style=\"font-family: \u5b8b\u4f53;\">\u5185\u5bb9\u6765\u505a\u4e00\u4e2a\u7b80\u5355\u7684\u8ba1\u7b97\u5668\uff0c\u901a\u8fc7\u8fd9\u4e2a\u8ba1\u7b97\u5668\uff0c\u8ba9\u5927\u5bb6\u80fd\u591f\u4f53\u4f1a\u5230\u6211\u5728\u7b2c\u4e00\u8282\u8bfe\u4e2d\u6240\u4ecb\u7ecd\u7684\u6807\u51c6\u7684<\/span>MVC<span style=\"font-family: \u5b8b\u4f53;\">\u6846\u67b6\u4e0e\u7528\u6237\u4ea4\u4e92\u7684\u4e00\u4e2a\u8fc7\u7a0b\u3002\u4e0b\u9762\uff0c\u5f00\u59cb\u4eca\u5929\u7684\u8bfe\u7a0b\u3002<\/span><\/div>\n<p><!--more--><\/p>\n<div align=\"left\"><span style=\"font-family: \u5b8b\u4f53;\">\u9996\u5148\uff0c\u8fd8\u662f\u548c\u6628\u5929\u4e00\u6837\uff0c\u89e3\u538b\u4e0b\u8f7d\u5230\u7684<\/span>CodeIgniter<span style=\"font-family: \u5b8b\u4f53;\">\u6846\u67b6\u6e90\u7801\uff0c\u66f4\u6539\u76ee\u5f55\u540d\u79f0\u4e3a<\/span>CI_02<span style=\"font-family: \u5b8b\u4f53;\">\uff08\u5982\u679c\u4e0d\u4f1a\u6b64\u6b65\u9aa4\uff0c\u8bf7\u770b\u7b2c\u4e00\u8bfe\uff09\u5e76\u8f7d\u5165\u5de5\u7a0b\u3002\u5728\u6628\u5929\u7684\u4f8b\u5b50\u4e2d\uff0c\u5927\u5bb6\u53ef\u4ee5\u770b\u5230\uff0c\u6700\u5148\u88ab\u4fee\u6539\u7684\u63a7\u5236\u5668\u662f<\/span>Welcome<span style=\"font-family: \u5b8b\u4f53;\">\u7c7b\uff0c\u53ef\u662f\u4e00\u822c\u6765\u8bf4\uff0c\u8bbf\u95ee\u4e00\u4e2a\u7f51\u7ad9\u4e0d\u5e94\u8be5\u662f\u5148\u8bbf\u95ee\u6839\u76ee\u5f55\u4e0b\u7684<\/span>index<span style=\"font-family: \u5b8b\u4f53;\">\u9875\u9762\u5417\uff1f\u5176\u5b9e\u8fd9\u91cc\u662f<\/span>CI<span style=\"font-family: \u5b8b\u4f53;\">\u6846\u67b6\u7684\u4e00\u4e2a\u529f\u80fd\uff0c\u4e5f\u662f\u5927\u591a\u6570<\/span>MVC<span style=\"font-family: \u5b8b\u4f53;\">\u6846\u67b6\u90fd\u6709\u7684\u529f\u80fd\uff0c\u90a3\u5c31\u662f\u8bbe\u7f6e\u9ed8\u8ba4\u63a7\u5236\u5668\uff0c\u5728<\/span>CI<span style=\"font-family: \u5b8b\u4f53;\">\u4e2d\u6709\u5f88\u591a\u914d\u7f6e\u6587\u4ef6\uff0c\u5176\u4e2d\u5728<\/span>config<span style=\"font-family: \u5b8b\u4f53;\">\u6587\u4ef6\u5939\u4e0b\u7684<\/span>routes.php<span style=\"font-family: \u5b8b\u4f53;\">\uff08\u8def\u7531\u914d\u7f6e\uff0c\u8fd9\u91cc\u5199\u7684\u591a\u6e05\u695a\u554a\uff09\u6587\u4ef6\u91cc\uff0c\u5927\u5bb6\u53ef\u4ee5\u770b\u5230\u8fd9\u6837\u4e00\u884c\u4ee3\u7801<\/span><\/div>\n<div align=\"left\">\u00a0<code>$route['default_controller'] = \"welcome\";<\/code><\/div>\n<div align=\"left\"><span style=\"font-family: \u5b8b\u4f53;\">\u8fd9\u884c\u4ee3\u7801\u7684\u4f5c\u7528\u5c31\u662f\u914d\u7f6e\u9ed8\u8ba4\u7684\u63a7\u5236\u5668\uff0c\u4e3a\u4e86\u8ba9\u5927\u5bb6\u80fd\u591f\u66f4\u597d\u7684\u5b66\u4e60\u5230<\/span>CI<span style=\"font-family: \u5b8b\u4f53;\">\u6846\u67b6\uff0c\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06\u8fd9\u884c\u4ee3\u7801\u4fee\u6539\u4e3a<\/span><\/div>\n<div align=\"left\"><code>$route['default_controller'] = \"calculate\";<\/code><\/div>\n<div align=\"left\"><span style=\"font-family: \u5b8b\u4f53;\">\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u521b\u5efa\u5c5e\u4e8e\u6211\u4eec\u81ea\u5df1\u7684<\/span>calculate<span style=\"font-family: \u5b8b\u4f53;\">\u63a7\u5236\u5668\uff0c\u5728<\/span>controllers<span style=\"font-family: \u5b8b\u4f53;\">\u6587\u4ef6\u5939\u4e0b\uff0c\u65b0\u5efa\u4e00\u4e2a<\/span>php<span style=\"font-family: \u5b8b\u4f53;\">\u6587\u4ef6\uff0c\u6587\u4ef6\u540d\u662f<\/span>calculate.php<span style=\"font-family: \u5b8b\u4f53;\">\uff0c\u7136\u540e\u4e66\u5199\u91cc\u9762\u7684\u4ee3\u7801<\/span><\/div>\n<div align=\"left\">\n<code><br \/>\n&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');<br \/>\n\/*<br \/>\n* \u8ba1\u7b97\u63a7\u5236\u5668\uff0c\u7c7b\u540d\u9996\u5b57\u6bcd\u5fc5\u987b\u5927\u5199\uff0c\u6240\u6709\u7684\u63a7\u5236\u5668\u5fc5\u987b\u7ee7\u627f\u81eaCI_Controller\u7c7b<br \/>\n*\/<br \/>\nclass Calculate extends CI_Controller {<br \/>\n\/\/ \u6784\u9020\u65b9\u6cd5<br \/>\nfunction __construct() {<br \/>\nparent::__construct();<br \/>\n}\/\/ \u9ed8\u8ba4\u65b9\u6cd5<br \/>\nfunction index() {<br \/>\n\/\/ \u52a0\u8f7dcalculate_view\u89c6\u56fe<br \/>\n$this-&gt;load-&gt;view('calculate_view');<br \/>\n}<br \/>\n}\/* End of file calculate.php *\/<br \/>\n\/* Location: .\/application\/controllers\/calculate.php *\/<br \/>\n<\/code><\/p>\n<div align=\"left\"><span style=\"font-family: \u5b8b\u4f53;\">\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u6ce8\u610f\u5230\uff0c\u6211\u4eec\u7684\u7c7b\u540d\u4e0e\u6587\u4ef6\u540d\u540c\u540d\uff0c\u4f46\u9996\u5b57\u6bcd\u662f\u5927\u5199\u7684\uff0c\u8fd9\u662f<\/span>CI<span style=\"font-family: \u5b8b\u4f53;\">\u7684\u89c4\u5219\uff0c\u5fc5\u987b\u8fd9\u6837\u505a\uff0c\u800c\u4e14\uff0c\u6240\u6709\u7684\u63a7\u5236\u5668\u90fd\u5fc5\u987b\u8981\u7ee7\u627f\u81ea<\/span>CI_Controller<span style=\"font-family: \u5b8b\u4f53;\">\u7c7b\uff0c\u53e6\u5916\uff0c\u53ef\u4ee5\u770b\u5230\uff0c\u6211\u4eec\u5728\u6587\u4ef6\u7ed3\u675f\u7684\u5730\u65b9\u53ea\u6709\u4e24\u884c\u6ce8\u91ca\uff0c\u5e76\u6ca1\u6709<\/span>PHP<span style=\"font-family: \u5b8b\u4f53;\">\u7684\u7ed3\u675f\u6807\u7b7e\u201c<\/span>?&gt;<span style=\"font-family: \u5b8b\u4f53;\">\u201d\uff0c\u5728\u8fd9\u91cc\u4e0d\u5bf9\u6b64\u505a\u8fc7\u591a\u89e3\u91ca\uff0c\u53ea\u662f<\/span>CI<span style=\"font-family: \u5b8b\u4f53;\">\u63a8\u8350\u8fd9\u6837\u5199\uff0c\u5982\u679c\u5927\u5bb6\u5bf9\u8fd9\u70b9\u611f\u5174\u8da3\uff0c\u6211\u4f1a\u5728\u540e\u9762\u7684\u8bfe\u7a0b\u4e2d\u8bb2\u5230\u3002<\/span><\/div>\n<p>&nbsp;<\/p>\n<div align=\"left\"><span style=\"font-family: \u5b8b\u4f53;\">\u5728\u4e0a\u9762\u7684\u63a7\u5236\u5668\u5f53\u4e2d\u52a0\u8f7d\u4e86\u4e00\u4e2a\u89c6\u56fe\uff0c\u4f46\u662f\u8fd9\u4e2a\u89c6\u56fe\u73b0\u5728\u8fd8\u6ca1\u6709\uff0c\u6ca1\u5173\u7cfb\uff0c\u73b0\u5728\u6211\u4eec\u5c31\u6765\u52a8\u624b\u5199\u8fd9\u4e2a\u89c6\u56fe\uff0c\u5728<\/span>views<span style=\"font-family: \u5b8b\u4f53;\">\u6587\u4ef6\u5939\u4e0b\u65b0\u5efa\u4e00\u4e2a<\/span>php<span style=\"font-family: \u5b8b\u4f53;\">\u6587\u4ef6\uff0c\u6587\u4ef6\u540d\u4e3a<\/span>calculate_view.php<span style=\"font-family: \u5b8b\u4f53;\">\uff0c\u6253\u5f00\u6587\u4ef6\uff0c\u4e66\u5199\u5177\u4f53\u7684\u4ee3\u7801<\/span><\/div>\n<\/div>\n<div align=\"left\"><\/div>\n<div align=\"left\">\n<code><br \/>\n&lt;!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd\"&gt;<br \/>\n&lt;html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/&gt;<br \/>\n&lt;title&gt;\u7f51\u9875\u8ba1\u7b97\u5668&lt;\/title&gt;<br \/>\n&lt;style type=\"text\/css\"&gt;<br \/>\n#calculators {<br \/>\nmargin: 10% auto;<br \/>\nwidth:430px;<br \/>\nborder:1px solid #000;<br \/>\n}<br \/>\n&lt;\/style&gt;<br \/>\n&lt;\/head&gt;&lt;body&gt;<br \/>\n&lt;div id=\"calculators\"&gt;<br \/>\n&lt;form action=\"\/CI_02\/index.php\/calculate\/count\" method=\"post\"&gt;<br \/>\n&lt;input type=\"text\" name=\"num1\" id=\"num1\" \/&gt;<br \/>\n&lt;select name=\"operate\" id=\"operate\"&gt;<br \/>\n&lt;option value=\"+\"&gt;+&lt;\/option&gt;<br \/>\n&lt;option value=\"-\"&gt;-&lt;\/option&gt;<br \/>\n&lt;option value=\"x\"&gt;x&lt;\/option&gt;<br \/>\n&lt;option value=\"\u00f7\"&gt;\u00f7&lt;\/option&gt;<br \/>\n&lt;\/select&gt;<br \/>\n&lt;input type=\"text\" name=\"num2\" id=\"num2\" \/&gt;<br \/>\n&lt;input type=\"submit\" value=\"\u8ba1\u7b97\" \/&gt;<br \/>\n&lt;\/form&gt;<br \/>\n&lt;\/div&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<br \/>\n<\/code><\/p>\n<p><span style=\"font-family: \u5b8b\u4f53;\">\u5728\u4e0a\u9762\u7684\u8868\u5355\u4e2d\uff0c\u6211\u4eec\u7684\u63d0\u4ea4\u8def\u5f84\u6307\u5411\u7684\u5176\u5b9e\u662f<\/span>calculate<span style=\"font-family: \u5b8b\u4f53;\">\u7c7b\u4e2d\u7684\u4e00\u4e2a\u65b9\u6cd5\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u7684\u540d\u5b57\u5c31\u662f<\/span>count<span style=\"font-family: \u5b8b\u4f53;\">\uff0c\u5173\u4e8e<\/span>CI<span style=\"font-family: \u5b8b\u4f53;\">\u6846\u67b6\u8def\u5f84\u7684\u89c4\u5219\uff0c\u6211\u5c06\u5728\u4e0b\u4e00\u8bb2\u4e2d\u8be6\u7ec6\u4ecb\u7ecd\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u6765\u4e66\u5199<\/span>controller<span style=\"font-family: \u5b8b\u4f53;\">\u4e2d\u5bf9\u5e94\u7684\u4ee3\u7801\uff0c\u5728<\/span>calculate<span style=\"font-family: \u5b8b\u4f53;\">\u63a7\u5236\u5668\u4e2d\u52a0\u5165\u5982\u4e0b\u7684\u51fd\u6570\uff1a<\/span><\/p>\n<p><code><br \/>\nfunction count() {<br \/>\n\/\/ \u4f7f\u7528\u8f93\u5165\u7c7b\u63a5\u6536\u53c2\u6570<br \/>\n<span class=\"katex math inline\">num1 =<\/span>this-&gt;input-&gt;post('num1');<br \/>\n<span class=\"katex math inline\">op =<\/span>this-&gt;input-&gt;post('operate');<br \/>\n<span class=\"katex math inline\">num2 =<\/span>this-&gt;input-&gt;post('num2');<br \/>\nif (is_numeric(<span class=\"katex math inline\">num1) &amp;&amp; is_numeric(<\/span>num2)) {<br \/>\n\/\/ \u5982\u679c\u4e24\u4e2a\u6570\u8f93\u5165\u5747\u4e3a\u6570\u5b57\uff0c\u5219\u8c03\u7528calculate_model\u6a21\u578b\u4e0b\u7684count\u65b9\u6cd5<br \/>\n<span class=\"katex math inline\">result =<\/span>this-&gt;calculate_model-&gt;count(<span class=\"katex math inline\">num1,<\/span>num2, $op);<br \/>\n}<br \/>\n}<br \/>\n<\/code><\/p>\n<p><span style=\"font-family: \u5b8b\u4f53;\">\u6211\u4eec\u770b\u5230\u5728\u63a7\u5236\u5668\u7684\u4ee3\u7801\u4e2d\uff0c\u8c03\u7528\u4e86<\/span>calculate_model<span style=\"font-family: \u5b8b\u4f53;\">\u6a21\u578b\u4e0b\u9762\u7684<\/span>count<span style=\"font-family: \u5b8b\u4f53;\">\u65b9\u6cd5\uff0c\u4f46\u662f\u5728\u8c03\u7528\u6a21\u578b\u4e4b\u524d\uff0c\u63a7\u5236\u5668\u5fc5\u987b\u5148\u8981\u52a0\u8f7d\u51fd\u6570\uff0c\u6240\u4ee5\uff0c\u9700\u8981\u5728\u63a7\u5236\u5668\u7684\u6784\u9020\u51fd\u6570\u4e2d\uff0c\u52a0\u5165\u5982\u4e0b\u4ee3\u7801\uff1a<\/span><\/p>\n<p>$this-&gt;load-&gt;model(&#8216;calculate_model&#8217;);<\/p>\n<p><span style=\"font-family: \u5b8b\u4f53;\">\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c31\u6309\u7167\u63a7\u5236\u5668\u91cc\u9762\u7684\u8c03\u7528\uff0c\u521b\u5efa\u6211\u4eec\u7684<\/span>calculate_model<span style=\"font-family: \u5b8b\u4f53;\">\u6a21\u578b\u548c<\/span>count<span style=\"font-family: \u5b8b\u4f53;\">\u65b9\u6cd5\uff0c\u6240\u6709\u7684\u6a21\u578b\u90fd\u662f\u653e\u5728<\/span>models<span style=\"font-family: \u5b8b\u4f53;\">\u6587\u4ef6\u5939\u4e0b\u7684\uff0c\u6240\u4ee5\uff0c\u6211\u4eec\u9700\u8981\u5728<\/span>models<span style=\"font-family: \u5b8b\u4f53;\">\u6587\u4ef6\u5939\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<\/span>calculate_model.php<span style=\"font-family: \u5b8b\u4f53;\">\u7684\u6587\u4ef6\uff0c\u521b\u5efa\u597d\u540e\uff0c\u6211\u4eec\u6765\u4e66\u5199<\/span>model<span style=\"font-family: \u5b8b\u4f53;\">\u7aef\u7684\u4ee3\u7801\uff1a<\/span><\/p>\n<p><code><br \/>\n&lt;?php<br \/>\n\/**<br \/>\n* \u8ba1\u7b97\u6a21\u578b\uff0c\u7c7b\u540d\u9996\u5b57\u6bcd\u5fc5\u987b\u5927\u5199\uff0c\u6240\u6709\u7684\u6a21\u578b\u5fc5\u987b\u7ee7\u627f\u81eaCI_Model\u7c7b<br \/>\n*\/<br \/>\nclass Calculate_model extends CI_Model {<br \/>\nfunction __construct() {<br \/>\nparent::__construct();<br \/>\n}<br \/>\n\/*<br \/>\n* \u8ba1\u7b97\u51fd\u6570<br \/>\n*\/<br \/>\nfunction count(<span class=\"katex math inline\">num1,<\/span>num2, <span class=\"katex math inline\">op) {<br \/>\nif (<\/span>op == \"+\") {<br \/>\nreturn <span class=\"katex math inline\">num1 +<\/span>num2;<br \/>\n}else if (<span class=\"katex math inline\">op == \"-\") {<br \/>\nreturn<\/span>num1 - <span class=\"katex math inline\">num2;<br \/>\n}else if (<\/span>op == \"x\") {<br \/>\nreturn <span class=\"katex math inline\">num1 *<\/span>num2;<br \/>\n}else if (<span class=\"katex math inline\">op == \"\u00f7\" &amp;&amp;<\/span>num2 != 0) {<br \/>\nreturn <span class=\"katex math inline\">num1 \/ 1.0 \/<\/span>num2;<br \/>\n}else {<br \/>\nreturn FALSE;<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n\/* End of file calculate_model.php *\/<br \/>\n\/* Location: .\/application\/models\/calculate_model.php *\/<br \/>\n<\/code><\/p>\n<\/div>\n<p><span style=\"font-family: \u5b8b\u4f53;\">\u73b0\u5728\uff0c\u5df2\u7ecf\u8fdb\u884c\u5230\u4e86\u6a21\u578b\u5c06\u8ba1\u7b97\u7ed3\u679c\u8fd4\u56de\u7ed9\u4e86\u63a7\u5236\u5668\uff0c\u8fd8\u5269\u6700\u540e\u4e00\u6b65\uff0c\u5c31\u6784\u6210\u4e86\u4e00\u4e2a\u6807\u51c6\u7684\u3001\u5b8c\u6574\u7684<\/span>MVC<span style=\"font-family: \u5b8b\u4f53;\">\u6846\u67b6\u6267\u884c\u8fc7\u7a0b\uff0c\u90a3\u5c31\u662f\u63a7\u5236\u5668\u518d\u6b21\u52a0\u8f7d\u89c6\u56fe\u6765\u663e\u793a\u8ba1\u7b97\u7ed3\u679c\u3002\u6211\u4eec\u9700\u8981\u5728<\/span>views<span style=\"font-family: \u5b8b\u4f53;\">\u6587\u4ef6\u5939\u4e0b\u521b\u5efa\u4e00\u4e2a\u89c6\u56fe\uff08<\/span>PHP<span style=\"font-family: \u5b8b\u4f53;\">\u6587\u4ef6\uff09\uff0c\u53d6\u540d\u4e3a<\/span>result_view.php<span style=\"font-family: \u5b8b\u4f53;\">\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/span><\/p>\n<p><code><br \/>\n&lt;!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd\"&gt;<br \/>\n&lt;html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/&gt;<br \/>\n&lt;title&gt;\u7f51\u9875\u8ba1\u7b97\u5668&lt;\/title&gt;<br \/>\n&lt;style type=\"text\/css\"&gt;<br \/>\n#calculators {<br \/>\nmargin: 10% auto;<br \/>\nwidth:430px;<br \/>\nborder:1px solid #000;<br \/>\n}<br \/>\n&lt;\/style&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n&lt;div id=\"calculators\"&gt;<br \/>\n&lt;?php<br \/>\n\/\/ \u4ece\u63a7\u5236\u5668\u63a5\u6536\u6570\u636e\u5e76\u5bf9\u6570\u636e\u8fdb\u884c\u64cd\u4f5c<br \/>\nif (is_numeric(<span class=\"katex math inline\">num1) &amp;&amp; is_numeric(<\/span>num2) &amp;&amp; <span class=\"katex math inline\">op &amp;&amp;<\/span>result &amp;&amp; <span class=\"katex math inline\">result != FALSE) {<br \/>\necho<\/span>num1.\" \".<span class=\"katex math inline\">op.\" \".<\/span>num2.\" = \".$result.\"&lt;br \/&gt;\";<br \/>\n}else {<br \/>\necho \"\u8ba1\u7b97\u9519\u8bef&lt;br \/&gt;\";<br \/>\n}<br \/>\n?&gt;<br \/>\n&lt;a href=\"\/CI_02\"&gt;\u8fd4\u56de\u9996\u9875&lt;\/a&gt;<br \/>\n&lt;\/div&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<br \/>\n<\/code><\/p>\n<p><span style=\"font-family: \u5b8b\u4f53;\">\u5927\u5bb6\u53ef\u4ee5\u6ce8\u610f\u5230\uff0c\u5728\u8fd9\u4e2a\u89c6\u56fe\u4e2d\uff0c\u51fa\u73b0\u4e86<\/span>PHP<span style=\"font-family: \u5b8b\u4f53;\">\u4ee3\u7801\uff0c\u800c\u4e14\u51fa\u73b0\u4e86\u4e00\u4e9b\u53d8\u91cf\uff0c\u8fd9\u4e9b\u53d8\u91cf\u662f\u54ea\u6765\u7684\u5462\uff1f\u8fd9\u5c31\u662f\u4eca\u5929\u8981\u8bb2\u5230\u7684\u53e6\u4e00\u4e2a\u91cd\u70b9\uff0c\u7ed9\u89c6\u56fe\u6dfb\u52a0\u52a8\u6001\u6570\u636e\u3002\u5728\u89c6\u56fe\u7684\u4f7f\u7528\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u63a7\u5236\u5668\u7ed9\u89c6\u56fe\u6dfb\u52a0\u52a8\u6001\u6570\u636e\uff0c\u8fd9\u4e9b\u6570\u636e\u5728\u63a7\u5236\u5668\u91cc\u90fd\u662f\u4ee5\u6570\u7ec4\u952e\u503c\u5bf9\u7684\u5f62\u5f0f\u5b9a\u4e49\u7684\uff0c\u5728\u63a7\u5236\u5668\u52a0\u8f7d\u89c6\u56fe\u7684\u540c\u65f6\uff0c\u6570\u636e\u6570\u7ec4\u505a\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u89c6\u56fe\uff1b\u5728\u89c6\u56fe\u4e2d\uff0c\u6211\u4eec\u53ea\u9700\u8981\u77e5\u9053\u6570\u636e\u5728\u6570\u7ec4\u4e2d\u7684\u952e\u540d\u5c31\u53ef\u4ee5\u53d6\u5230\u60f3\u8981\u7684\u6570\u636e\u3002\u6bd4\u5982\uff0c\u5728\u63a7\u5236\u5668\u91cc\u5b9a\u4e49\u7684\u6570\u636e\u6570\u7ec4\u662f\uff1a<\/span><\/p>\n<p><code>$data = array('num1' =&gt; 1, 'num2' =&gt; 2, 'op' =&gt; +, 'result' =&gt; 3);<\/code><\/p>\n<p>\u90a3\u4e48\u5728\u89c6\u56fe\u4e2d\uff0c\u53ea\u9700\u8981\u77e5\u9053\u952e\u540d\uff0c\u5c31\u53ef\u4ee5\u53d6\u5f97\u76f8\u5bf9\u5e94\u7684\u6570\u636e\uff0c\u6bd4\u5982\uff1a<\/p>\n<p><code>echo <span class=\"katex math inline\">num1.\" \".<\/span>op.\" \".<span class=\"katex math inline\">num2.\" = \".<\/span>result.\"&lt;br \/&gt;\";<\/code><\/p>\n<p><span style=\"font-family: \u5b8b\u4f53;\">\u5199\u597d\u4e86\u7528\u4e8e\u663e\u793a\u8ba1\u7b97\u7ed3\u679c\u7684\u89c6\u56fe\uff0c\u4e5f\u5b66\u4f1a\u4e86\u600e\u6837\u7ed9\u89c6\u56fe\u6dfb\u52a0\u52a8\u6001\u6570\u636e\uff0c\u73b0\u5728\u53ea\u9700\u8981\u7a0d\u5fae\u4fee\u6539\u4e00\u4e0b\u524d\u9762\u5199\u597d\u7684\u63a7\u5236\u5668\u7684<\/span>count<span style=\"font-family: \u5b8b\u4f53;\">\u51fd\u6570\uff0c\u8ba1\u7b97\u7ed3\u679c\u5c31\u53ef\u4ee5\u663e\u793a\u5728<\/span>result_view<span style=\"font-family: \u5b8b\u4f53;\">\u89c6\u56fe\u4e0a\u4e86\uff0c\u5bf9<\/span>count<span style=\"font-family: \u5b8b\u4f53;\">\u51fd\u6570\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/span><\/p>\n<p><code><br \/>\nfunction count() {<br \/>\n\/\/ \u4f7f\u7528\u8f93\u5165\u7c7b\u63a5\u6536\u53c2\u6570<br \/>\n<span class=\"katex math inline\">num1 =<\/span>this-&gt;input-&gt;post('num1');<br \/>\n<span class=\"katex math inline\">op =<\/span>this-&gt;input-&gt;post('operate');<br \/>\n<span class=\"katex math inline\">num2 =<\/span>this-&gt;input-&gt;post('num2');<br \/>\nif (is_numeric(<span class=\"katex math inline\">num1) &amp;&amp; is_numeric(<\/span>num2)) {<br \/>\n\/\/ \u5982\u679c\u4e24\u4e2a\u6570\u8f93\u5165\u5747\u4e3a\u6570\u5b57\uff0c\u5219\u8c03\u7528calculate_model\u6a21\u578b\u4e0b\u7684count\u65b9\u6cd5<br \/>\n<span class=\"katex math inline\">result =<\/span>this-&gt;calculate_model-&gt;count(<span class=\"katex math inline\">num1,<\/span>num2, <span class=\"katex math inline\">op);<br \/>\n\/\/ \u751f\u6210\u8981\u4f20\u7ed9\u89c6\u56fe\u7684\u6570\u636e<\/span>data = array('num1' =&gt; <span class=\"katex math inline\">num1, 'num2' =&gt;<\/span>num2, 'op' =&gt; <span class=\"katex math inline\">op, 'result' =&gt;<\/span>result);<br \/>\n\/\/ \u52a0\u8f7d\u89c6\u56fe<br \/>\n<span class=\"katex math inline\">this-&gt;load-&gt;view('result_view',<\/span>data);<br \/>\n}<br \/>\n}<br \/>\n<\/code><\/p>\n<div align=\"left\"><span style=\"font-family: \u5b8b\u4f53;\">\u53ef\u4ee5\u770b\u5230\uff0c\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u53ea\u662f\u5c06\u7528\u6237\u8f93\u5165\u7684\u6570\u5b57\u548c\u64cd\u4f5c\u7b26\u4ee5\u53ca\u6a21\u578b\u8fd4\u56de\u7684\u8ba1\u7b97\u7ed3\u679c\u653e\u5165<\/span>data<span style=\"font-family: \u5b8b\u4f53;\">\u6570\u7ec4\u4e2d\uff0c\u7136\u540e\u5c06\u6570\u7ec4\u505a\u4e3a\u52a0\u8f7d\u89c6\u56fe\u65f6\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\uff0c\u5c31\u53ef\u4ee5\u5b9e\u73b0\u5728\u89c6\u56fe\u4e2d\u663e\u793a\u8ba1\u7b97\u7ed3\u679c\u3002<\/span><\/div>\n<div align=\"left\"><span style=\"font-family: \u5b8b\u4f53;\">\u770b\u5230\u8fd9\u91cc\uff0c\u606d\u559c\u4f60\uff0c\u4f60\u5df2\u7ecf\u6210\u529f\u7684\u5b66\u4f1a\u4e86<\/span>MVC<span style=\"font-family: \u5b8b\u4f53;\">\u6846\u67b6\u7684\u57fa\u672c\u5185\u5bb9\uff0c\u5176\u5b9e\u4e00\u70b9\u90fd\u4e0d\u96be\uff0c\u5728\u63a5\u4e0b\u6765\u7684\u8bfe\u7a0b\u4e2d\uff0c\u6211\u5c06\u9010\u6b65\u8bb2\u89e3<\/span>CI<span style=\"font-family: \u5b8b\u4f53;\">\u6846\u67b6\u4e2d\u5176\u4ed6\u7c7b\u5e93\u548c\u8f85\u52a9\u51fd\u6570\u7684\u4f7f\u7528\u65b9\u6cd5\u3002<\/span><\/div>\n<p>&nbsp;<\/p>\n<div align=\"left\"><span style=\"font-family: \u5b8b\u4f53;\">\u603b\u7ed3\uff1a\u4eca\u5929\u5b66\u4e60\u4e86<\/span>CI<span style=\"font-family: \u5b8b\u4f53;\">\u6846\u67b6\u7684<\/span>MVC<span style=\"font-family: \u5b8b\u4f53;\">\u6846\u67b6\u7684\u57fa\u672c\u5185\u5bb9\uff0c\u5230\u6b64\u4f4d\u7f6e\uff0c<\/span>MVC<span style=\"font-family: \u5b8b\u4f53;\">\u7684\u57fa\u672c\u529f\u80fd\u5df2\u7ecf\u5b9e\u73b0\uff0c\u4e0b\u4e00\u8bb2\u7684\u5185\u5bb9\u662f<\/span>URI<span style=\"font-family: \u5b8b\u4f53;\">\u4ee5\u53ca\u4f7f\u7528<\/span>ajax<span style=\"font-family: \u5b8b\u4f53;\">\u3002<\/span><\/div>\n<p>&nbsp;<\/p>\n<div align=\"left\"><span style=\"font-family: \u5b8b\u4f53;\">\u7b2c\u4e8c\u8bfe\u6e90\u4ee3\u7801\u4e0b\u8f7d\u5730\u5740\uff1a<\/span><\/div>\n<div align=\"left\"><!--reply start-->http:\/\/pan.baidu.com\/s\/1eQeLSem<!--reply end--><\/div>\n  \n  \n  ","protected":false},"excerpt":{"rendered":"<p>\u7b2c\u4e8c\u8bfe \u521d\u59cbMVC \u4eca\u5929\u7684\u4e3b\u8981\u5185\u5bb9\u662f\uff0c\u4f7f\u7528CodeIgniter\u6846\u67b6\u5b8c\u6574\u7684MVC\u5185\u5bb9\u6765\u505a\u4e00\u4e2a\u7b80\u5355\u7684\u8ba1\u7b97\u5668\uff0c\u901a\u8fc7&hellip;<a href=\"https:\/\/www.softeng.cn\/?p=53\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">CodeIgniter\u6846\u67b6\u5165\u95e8\u6559\u7a0b\u2014\u2014\u7b2c\u4e8c\u8bfe \u521d\u59cbMVC<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[9,6,10],"class_list":["post-53","post","type-post","status-publish","format-standard","hentry","category-3","tag-codeigniter","tag-php","tag-10"],"_links":{"self":[{"href":"https:\/\/www.softeng.cn\/index.php?rest_route=\/wp\/v2\/posts\/53"}],"collection":[{"href":"https:\/\/www.softeng.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.softeng.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.softeng.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.softeng.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=53"}],"version-history":[{"count":20,"href":"https:\/\/www.softeng.cn\/index.php?rest_route=\/wp\/v2\/posts\/53\/revisions"}],"predecessor-version":[{"id":73,"href":"https:\/\/www.softeng.cn\/index.php?rest_route=\/wp\/v2\/posts\/53\/revisions\/73"}],"wp:attachment":[{"href":"https:\/\/www.softeng.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=53"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.softeng.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=53"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.softeng.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=53"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}