<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Becomin&#039; Charles &#187; 心得体会</title>
	<atom:link href="http://sexywp.com/cata/something-about-daily-work/%e5%bf%83%e5%be%97%e4%bd%93%e4%bc%9a/feed" rel="self" type="application/rss+xml" />
	<link>http://sexywp.com</link>
	<description>Building another myself~~</description>
	<lastBuildDate>Thu, 19 Apr 2012 16:32:29 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-beta4-20805</generator>
		<item>
		<title>面向过程与面向对象</title>
		<link>http://sexywp.com/process-oriented-and-object-oriented-design.htm</link>
		<comments>http://sexywp.com/process-oriented-and-object-oriented-design.htm#comments</comments>
		<pubDate>Thu, 19 Apr 2012 16:32:29 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[工作相关]]></category>
		<category><![CDATA[心得体会]]></category>
		<category><![CDATA[experience]]></category>
		<category><![CDATA[project]]></category>

		<guid isPermaLink="false">http://sexywp.com/?p=478</guid>
		<description><![CDATA[回到家已经超过23点了，想想也做不了什么事情了，那就把路上跟同事讨论的问题，拿出来写一写。又是一个老生常谈的问题，就是到底是面向对象还是面向过程？其实关于这个问题，本不该有什么疑惑的，但是随着最近一个项目的经验，我又产生了一些新的看法。

自从我学习了面向对象，我就好像掌握了一个得心应手的工具，感觉在处理各种问题的时候无往而不利，虽然偶尔也会有些迷惑，但是终归无伤大雅。这样二了一段日子以后，我终于接触到了设计模式，以及有机会见识了一些真正复杂的项目，发现面向对象很多时候，都是一种艰难地抉择。于是，对面向对象开始有了敬畏之心，并一直认真地思考这里面的问题，认认真真去实践面向对象设计，分析别人的写的代码，越发感觉到还有很多路要走。

<span class="readmore"><a href="http://sexywp.com/process-oriented-and-object-oriented-design.htm" title="面向过程与面向对象">Keep Reading --- 2091 words totally</a></span><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="工作中常用的Linux命令集锦" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Flinux-commands-used-when-working.htm&from=http%3A%2F%2Fsexywp.com%2Fprocess-oriented-and-object-oriented-design.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">工作中常用的Linux命令集锦</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Yii框架的Log系统的分析" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fhow-to-use-log-in-yii-framework.htm&from=http%3A%2F%2Fsexywp.com%2Fprocess-oriented-and-object-oriented-design.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9184865.jpg" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Yii框架的Log系统的分析</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="给SVN客户端配置代理服务器" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fuse-proxy-in-ur-svn-client.htm&from=http%3A%2F%2Fsexywp.com%2Fprocess-oriented-and-object-oriented-design.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/13/12123060.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">给SVN客户端配置代理服务器</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="【边学边用】PHP5函数参数的按引用传递" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm&from=http%3A%2F%2Fsexywp.com%2Fprocess-oriented-and-object-oriented-design.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">【边学边用】PHP5函数参数的按引用传递</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="关于Push Mail的种种" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fwhat-is-push-mail.htm&from=http%3A%2F%2Fsexywp.com%2Fprocess-oriented-and-object-oriented-design.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">关于Push Mail的种种</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>回到家已经超过23点了，想想也做不了什么事情了，那就把路上跟同事讨论的问题，拿出来写一写。又是一个老生常谈的问题，就是到底是面向对象还是面向过程？其实关于这个问题，本不该有什么疑惑的，但是随着最近一个项目的经验，我又产生了一些新的看法。<span id="more-478"></span></p>
<p>自从我学习了面向对象，我就好像掌握了一个得心应手的工具，感觉在处理各种问题的时候无往而不利，虽然偶尔也会有些迷惑，但是终归无伤大雅。这样二了一段日子以后，我终于接触到了设计模式，以及有机会见识了一些真正复杂的项目，发现面向对象很多时候，都是一种艰难地抉择。于是，对面向对象开始有了敬畏之心，并一直认真地思考这里面的问题，认认真真去实践面向对象设计，分析别人的写的代码，越发感觉到还有很多路要走。</p>
<p>习惯了用对象思考以后，一旦有实际问题要解决的时候，已经习惯了按照面向对象的思路开始思考，直到最近。在项目中遇到了大段的面向过程的代码，以及贯穿在其背后的设计思想。心中很不以为然，轮到自己操作的时候，还是用上了面向对象的方法，今天我和同事聊起这个问题的时候，我还是换位思考了一下，才明白了面向过程远没有我想象的那样不堪，以及那样容易。</p>
<p>其实面向过程的设计思路，说白了就是自顶向下，逐步求精。但是这么简单八个字，如果放在一个函数里，估计初学写程序的人，也是可以驾驭的，但是如果放到一个数万行代码的项目里，驾驭起来远超想象的困难。我为什么厌恶面向过程的设计方法，我仔细反思了一下，可能根本原因，还是我没法在数万行代码的项目里，很好的驾驭这个方法，已经搞不清楚应该先干什么后干什么了，很容易把事情搞得一团糟，所以才不喜欢这样做。</p>
<p>在稍大的项目中，第一个面临的问题，就是分工合作。而这也是我认为面向过程方法能带来的主要好处所在：第一，项目开发人员水平良莠不齐，有些人懂面向对象有些人不懂，有些理解深刻，有些理解浅薄，有些干脆不会；这种情况下，面向过程的方法最容易推广，也容易掌控，分工下去以后，面向过程其实就是写好一个个函数，最糟糕就是某些函数写得漏洞百出，但是仍旧能够掌控，修复的时候，总也还有办法；第二，利于任务分解，只要想好整体的业务流程，按照功能往上堆叠代码就好了，每个人一块，只要搞清输入输出，就可以开工动手；第三，平行扩容，这个说的是团队扩容，项目发展过程中，需求难免快速变化，如果在紧要时候，难免人手不足，这个时候迅速抽调人力，扑倒项目上，马上就可以着手，只要看清楚function specification，就可以立刻贡献力量，整个团队会因为人手的变多，实现生产力提高；第四，健壮性好，出错的往往只是函数，修复即可，牵一发而动全身的情况少。</p>
<p>要实现我说的这些优点，其实还是非常困难的，需要思路非常清晰的技术领导，正确把握设计流程，关键处把关。所以，我说我驾驭不了，就是这个原因，不知道关键点在哪里，也难以有相当的技术敏感性来预知问题。</p>
<p>劣势是什么呢？第一，代码复用性差，因为设计不可能精细入微，所以代码难免抽象有限，出现大量的重复，比如遍历某个数据结构，因为是通用数据结构，也是和别的函数传递消息用的，免不了每个函数都要去遍历一次，这也是没有办法的事情，要实现不重复，可能设计上的要求要提高一个数量级了；第二，代码混乱，因为分工，乱序能力强，带来的弱势就是，代码会比较混乱，比如顶层和底层并行开发，导致顶层开工的时候，底层还没有就位，不得不先用一些替代方案，等到底层好了对接发现有偏差，不得不打一些补丁代码来修复，最后结局就是混乱；第三，一致性差，因为最小单位是函数，局部变量的要求不高，所以会在代码里看到各式各样的局部变量。</p>
<p>这些劣势都是很容易出现的，因为这是这个方法论本身的缺陷。</p>
<p>面向对象的好处是一开始，就强迫大家用逻辑性比较强，高内聚，低耦合的思路去思考问题，代码的内聚度高，可重用性好，重复少。然后，代码总量会降低。容易写出思路比较清楚的代码。</p>
<p>劣势也是相当明显的。第一就是没法在团队中很好的推广，对每个成员要求比较高；第二，不利于任务分解，因为面向对象设计任务更加繁重，如果要任务分解，势必要确定接口，如果没法很全面地定下接口，那上下游分工就比较困难；第三，扩容难，因为代码对全局观要求比较高，临时加入项目的人，因为没法全面了解所有对象的功能，势必上手比较慢；第四，就是设计上的失误牵扯会比较广，因为都是对象间交互，如果一个对象有问题，牵扯到上下游都要改。第五，代码逻辑内聚度高了，但是业务逻辑代码分散了，比如MVC，同一个业务逻辑相关内容，数据在M里，展现在V里，控制在V里，改一个业务逻辑，最优情况，是改三个文件，事实平均情况下，远高于三个，一般都是4、5个或者8、9个。</p>
<p>我最后想说的就是，一群人做事和一个人做事是很不一样的，你不得不顾及到整个团队的情况，兼顾每人的能力，偏好。人越多，越难兼顾。还有就是在实际项目开发中，很多东西都要受到限制，这非常糟糕，但是没法对抗。不得不考虑各种因素。如果一味地只考虑方法论本身的先进与否，一味地考虑自己的偏好，可能你离一个技术领导的距离还是比较遥远的。做个小兵容易，领导团队困难啊～</p>
<p>就是一点个人领悟，有点语无伦次，以后闲下来，再好好整理，诸君见谅了。</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="工作中常用的Linux命令集锦" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Flinux-commands-used-when-working.htm&from=http%3A%2F%2Fsexywp.com%2Fprocess-oriented-and-object-oriented-design.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">工作中常用的Linux命令集锦</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Yii框架的Log系统的分析" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fhow-to-use-log-in-yii-framework.htm&from=http%3A%2F%2Fsexywp.com%2Fprocess-oriented-and-object-oriented-design.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9184865.jpg" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Yii框架的Log系统的分析</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="给SVN客户端配置代理服务器" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fuse-proxy-in-ur-svn-client.htm&from=http%3A%2F%2Fsexywp.com%2Fprocess-oriented-and-object-oriented-design.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/13/12123060.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">给SVN客户端配置代理服务器</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="【边学边用】PHP5函数参数的按引用传递" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm&from=http%3A%2F%2Fsexywp.com%2Fprocess-oriented-and-object-oriented-design.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">【边学边用】PHP5函数参数的按引用传递</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="关于Push Mail的种种" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fwhat-is-push-mail.htm&from=http%3A%2F%2Fsexywp.com%2Fprocess-oriented-and-object-oriented-design.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">关于Push Mail的种种</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/experience" title="experience" rel="tag">experience</a>, <a href="http://sexywp.com/tags/project" title="project" rel="tag">project</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/process-oriented-and-object-oriented-design.htm/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>【边学边用】PHP5函数参数的按引用传递</title>
		<link>http://sexywp.com/php5-pass-param-by-ref.htm</link>
		<comments>http://sexywp.com/php5-pass-param-by-ref.htm#comments</comments>
		<pubDate>Fri, 26 Aug 2011 14:07:14 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[工作相关]]></category>
		<category><![CDATA[心得体会]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[usage]]></category>

		<guid isPermaLink="false">http://sexywp.com/?p=454</guid>
		<description><![CDATA[PHP是支持引用的，但是关于一个变量什么时候是引用，什么时候是值，我脑子里总是迷迷糊糊的，所以，想用引用的时候，就会不自觉地在所有的地方加上&#038;符号，真的很累赘。为了缓解这个问题，我特意写了下面这个代码片段来增进自己的理解。起初，我对这个东西的理解是，对于对象来说，PHP5就是按照引用传递的。但是我现在想，可能事情不是这么一回事情。下面的代码片段中，$obj其实是A的对象的一个引用，可以理解成一个指针，函数参数$o，其实还是对$obj的拷贝，只是拷贝的是引用本身，也即，$o其实是$obj的拷贝，只是由于其拷贝了$obj，所以，$o也指向A的对象。两个指针指向一个地方，这也是为什么函数changeObj可以改变A的对象的原因。我想，这样大概从技术来说，会更加合理一点。

<span class="readmore"><a href="http://sexywp.com/php5-pass-param-by-ref.htm" title="【边学边用】PHP5函数参数的按引用传递">Keep Reading --- 315 words totally</a></span><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Flet-php5-support-readline.htm&from=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Dedian 5的PHP包缺少readline支持</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fdeprecated-features-in-php-5-3.htm&from=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">PHP 5.3.x中弃用的特性 Deprecated</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Flinux-commands-used-when-working.htm&from=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">工作中常用的Linux命令集锦</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fphp-return.htm&from=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">[Tips] PHP中return的用法</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fvideo-guide-to-use-yii-framework.htm&from=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">视频教程：使用Yii框架开发Blog</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>PHP是支持引用的，但是关于一个变量什么时候是引用，什么时候是值，我脑子里总是迷迷糊糊的，所以，想用引用的时候，就会不自觉地在所有的地方加上&#038;符号，真的很累赘。为了缓解这个问题，我特意写了下面这个代码片段来增进自己的理解。起初，我对这个东西的理解是，对于对象来说，<a href="http://sexywp.com/tags/php" class="st_tag internal_tag" rel="tag" title="标签 PHP 下的日志">PHP</a>5就是按照引用传递的。但是我现在想，可能事情不是这么一回事情。下面的代码片段中，$obj其实是A的对象的一个引用，可以理解成一个指针，函数参数$o，其实还是对$obj的拷贝，只是拷贝的是引用本身，也即，$o其实是$obj的拷贝，只是由于其拷贝了$obj，所以，$o也指向A的对象。两个指针指向一个地方，这也是为什么函数changeObj可以改变A的对象的原因。我想，这样大概从技术来说，会更加合理一点。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Blue;">&lt;?php</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">class</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">A</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Green;">public</span><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">$a</span><span style="color: Gray;">=</span><span style="color: Maroon;">1</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Green;">public</span><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">$b</span><span style="color: Gray;">=</span><span style="color: Maroon;">1</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">$obj</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">A</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">var_dump</span><span style="color: Olive;">(</span><span style="color: #00008b;">$obj</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; </span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">changeObj</span><span style="color: Olive;">(</span><span style="color: #00008b;">$o</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #00008b;">$o</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">a</span><span style="color: Gray;"> = </span><span style="color: Maroon;">3</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #00008b;">$o</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">b</span><span style="color: Gray;"> = </span><span style="color: Maroon;">5</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">changeObj</span><span style="color: Olive;">(</span><span style="color: #00008b;">$obj</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">var_dump</span><span style="color: Olive;">(</span><span style="color: #00008b;">$obj</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li></ol></div></div>
<p>执行结果如下：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">object(A)#1 (2) {</li>
<li>&nbsp; [&quot;a&quot;]=&gt;</li>
<li>&nbsp; int(1)</li>
<li>&nbsp; [&quot;b&quot;]=&gt;</li>
<li>&nbsp; int(1)</li>
<li>}</li>
<li>object(A)#1 (2) {</li>
<li>&nbsp; [&quot;a&quot;]=&gt;</li>
<li>&nbsp; int(3)</li>
<li>&nbsp; [&quot;b&quot;]=&gt;</li>
<li>&nbsp; int(5)</li>
<li>}</li></ol></div>
<p>然后再看一个普通变量的引用传递的例子，这个例子里面使用的是原生的整型变量，然后函数changeInt的函数声明里，也用一般方法声明参数，普通的调用，我们发现函数不能改变$x和$y的值，这符合我们的预期，但是第二个形式的调用，就是传参数时候，带上引用标志&#038;，结果我们发现，$x和$y的值也改变了，这是为什么呢，跟上面的例子是一个原因，函数的形式参数a和b其实是$x和$y的引用的拷贝，所以a和b也指向x和y，所以，a和b可以改变x和y的值。再看最下面的一种形式，这种是我认为的真正的按照引用传递参数。非常的绕乎对吧？我也觉得如此，确实太过灵活了。确实不利于学习和理解，代码也不容易维护，如果真的想用引用传递参数，推荐用最底下一种方式，明确告诉调用的人，这里其实是引用，千万别用changeInt(&#038;$x, &#038;$y);这种形式，这个代码散步在各处，将极难定位bug。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Blue;">&lt;?php</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">$x</span><span style="color: Gray;"> = </span><span style="color: Maroon;">1</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">$y</span><span style="color: Gray;"> = </span><span style="color: Maroon;">2</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; </span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">changeInt</span><span style="color: Olive;">(</span><span style="color: #00008b;">$a</span><span style="color: Gray;">, </span><span style="color: #00008b;">$b</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #00008b;">$a</span><span style="color: Gray;"> = </span><span style="color: Maroon;">3</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #00008b;">$b</span><span style="color: Gray;"> = </span><span style="color: Maroon;">4</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">changeInt</span><span style="color: Olive;">(</span><span style="color: #00008b;">$x</span><span style="color: Gray;">,</span><span style="color: #00008b;">$y</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">var_dump</span><span style="color: Olive;">(</span><span style="color: #00008b;">$x</span><span style="color: Gray;">, </span><span style="color: #00008b;">$y</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">$x = 1, $y = 2</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">changeInt</span><span style="color: Olive;">(</span><span style="color: Gray;">&amp;</span><span style="color: #00008b;">$x</span><span style="color: Gray;">, &amp;</span><span style="color: #00008b;">$y</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">var_dump</span><span style="color: Olive;">(</span><span style="color: #00008b;">$x</span><span style="color: Gray;">, </span><span style="color: #00008b;">$y</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">$x = 3, $y = 4</span></li>
<li><span style="color: Gray;">&nbsp; </span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">changeIntByRef</span><span style="color: Olive;">(</span><span style="color: Gray;">&amp;</span><span style="color: #00008b;">$a</span><span style="color: Gray;">, &amp;</span><span style="color: #00008b;">$b</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #00008b;">$a</span><span style="color: Gray;"> = </span><span style="color: Maroon;">5</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #00008b;">$b</span><span style="color: Gray;"> = </span><span style="color: Maroon;">6</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">changeIntByRef</span><span style="color: Olive;">(</span><span style="color: #00008b;">$x</span><span style="color: Gray;">, </span><span style="color: #00008b;">$y</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; </span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">var_dump</span><span style="color: Olive;">(</span><span style="color: #00008b;">$x</span><span style="color: Gray;">, </span><span style="color: #00008b;">$y</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">$x = 5, $y = 6</span></li></ol></div></div>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Flet-php5-support-readline.htm&from=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Dedian 5的PHP包缺少readline支持</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fdeprecated-features-in-php-5-3.htm&from=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">PHP 5.3.x中弃用的特性 Deprecated</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Flinux-commands-used-when-working.htm&from=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">工作中常用的Linux命令集锦</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fphp-return.htm&from=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">[Tips] PHP中return的用法</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fvideo-guide-to-use-yii-framework.htm&from=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">视频教程：使用Yii框架开发Blog</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/basic" title="basic" rel="tag">basic</a>, <a href="http://sexywp.com/tags/php" title="PHP" rel="tag">PHP</a>, <a href="http://sexywp.com/tags/usage" title="usage" rel="tag">usage</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/php5-pass-param-by-ref.htm/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ExtJS 4 的MVC</title>
		<link>http://sexywp.com/extjs-4-mvc.htm</link>
		<comments>http://sexywp.com/extjs-4-mvc.htm#comments</comments>
		<pubDate>Sat, 09 Jul 2011 17:39:44 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[心得体会]]></category>
		<category><![CDATA[analytics]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[yii]]></category>

		<guid isPermaLink="false">http://sexywp.com/?p=445</guid>
		<description><![CDATA[ExtJS是我听说了很久的一个js框架了，但是从来就没有用过，读研期间寝室里有个小哥在用，不过那时候醉心于WordPress开发，也懒得理会了。现在公司里，有个上线系统用到了这个框架中的一个TreePanel组件，整个界面上，就正中间扔了一个tree panel，而且不知道什么原因，CSS还有bug，把按钮都搞破了，弄得丑陋不堪，我于是自告奋勇，仔细调试，终于修复了那个显示上的bug，从此算是初次结识了ExtJS。它真正吸引我的原因是，它能够把富客户端应用的开发，从美工和基础交互中解放出来，只需要专注于业务逻辑开发即可，从而让后台工程师也能够有能力快速开发外观专业的网站应用系统。我觉得这真是功德无量的一个事情。（如果我直觉没错，Flex框架也是这一类东西，这也是我对其有兴趣的原因，当然还没有时间尝试）

<span class="readmore"><a href="http://sexywp.com/extjs-4-mvc.htm" title="ExtJS 4 的MVC">Keep Reading --- 1529 words totally</a></span><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="MVC就是个选择题" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fmvc-chose-where-to-put-your-code.htm&from=http%3A%2F%2Fsexywp.com%2Fextjs-4-mvc.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">MVC就是个选择题</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="MVC最佳实践" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fmvc-best-practice.htm&from=http%3A%2F%2Fsexywp.com%2Fextjs-4-mvc.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">MVC最佳实践</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="我对摆渡真的很无语啊" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fnothing-to-say.htm&from=http%3A%2F%2Fsexywp.com%2Fextjs-4-mvc.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/17/12736661.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">我对摆渡真的很无语啊</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="讨论：模板文件里哪些是必须的？" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Ftemplate-hierarchy.htm&from=http%3A%2F%2Fsexywp.com%2Fextjs-4-mvc.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/10/11648916.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">讨论：模板文件里哪些是必须的？</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Unnamed 1.23 中文语言包" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Flang-pack-to-unnamed-123.htm&from=http%3A%2F%2Fsexywp.com%2Fextjs-4-mvc.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/01/10482994.jpg" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Unnamed 1.23 中文语言包</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>ExtJS是我听说了很久的一个js框架了，但是从来就没有用过，读研期间寝室里有个小哥在用，不过那时候醉心于WordPress开发，也懒得理会了。现在公司里，有个上线系统用到了这个框架中的一个TreePanel组件，整个界面上，就正中间扔了一个tree panel，而且不知道什么原因，CSS还有bug，把按钮都搞破了，弄得丑陋不堪，我于是自告奋勇，仔细调试，终于修复了那个显示上的bug，从此算是初次结识了ExtJS。它真正吸引我的原因是，它能够把富客户端应用的开发，从美工和基础交互中解放出来，只需要专注于业务逻辑开发即可，从而让后台工程师也能够有能力快速开发外观专业的网站应用系统。我觉得这真是功德无量的一个事情。（如果我直觉没错，Flex框架也是这一类东西，这也是我对其有兴趣的原因，当然还没有时间尝试）<span id="more-445"></span></p>
<p><a href="https://picasaweb.google.com/lh/photo/6w-l2AcPyxIcU35pqAdwTA?feat=embedwebsite"><img src="https://lh6.googleusercontent.com/-NjYqHh6WjX0/ThiD-8_-xxI/AAAAAAAAB5w/jjqmfY8JrZE/s800/ExtJS%2525E5%2525AF%2525B9%2525E8%2525B1%2525A1%2525E5%252585%2525B3%2525E7%2525B3%2525BB%2525E5%25259B%2525BE.png" height="310" width="499" alt="ExtJS 4 MVC"/></a></p>
<p>据官网介绍，还有据同事<a href="http://www.showframework.com/" target="_blank">ishow</a>的描述，<a href="http://sexywp.com/tags/extjs-2" class="st_tag internal_tag" rel="tag" title="标签 extjs 下的日志">ExtJS</a> 4.x 是一个变化很大的版本，相比已经应用广泛的 3.x 来说，变了很多、新特性也很多，MVC就是它提供的新特性之一。由于我最近半年都在学习MVC模式（主要是使用Yii框架），所以这个名词更是引起了我浓厚的兴趣，这几天都在官网上看这个框架MVC的例子，直到今天，总算是摸着一点门道，于是画了上面那个图。这个四不像的图，是我个人对框架的理解的第一个具体化产物。</p>
<p>下面简单描述一下这个图。</p>
<p>1. 每个应用都有一个实体，就是Application对象实例，而每个应用同样也采用单一入口结构，有个快捷函数就是Ext.application({config})，创建一个Application对象实例，并且运行它；这里行为表现和Yii框架的Application看起来很像，创建一个实例，然后run；</p>
<p>2. Application在创建之初，会去加载Controller类，加载完毕后，会正式的lunch；</p>
<p>3. Application在lunch的时候，会创建一个Viewport对象实例，这个东西就像一个骨架一样，上面可以拼装各种View，具体说，就是各种布局形式和窗体控件，可以说是应用界面的载体；</p>
<p>4. Controller的角色完全是个粘合剂，它在加载之初，会帮忙加载跟其有关的Model，Store，View类，而其真正的作用，是通过一系列的事件处理函数，确定了每个View上面界面组件对用户交互行为的响应方法，可以说是一堆事件处理器函数的集合；这里面主要通过一个control成员函数来进行事件绑定，通过另一个叫ComponentQuery的组件，使用类似css selector的语法来定位界面上的组件，并为其绑定事件处理器；</p>
<p>5. Model是对抽象数据的具体化，或者可以这么理解，就是数据库里面的一行记录，到底是怎么变成一个对象的，将数据库字段变成了对象的属性的对应关系；而这里比Yii框架MVC模型多出来的东西，就是Store这个东西，在Yii框架里面，有强大的ORM系统，还有强大的AR将Model直接连接到了DB上，数据一出来就直接变成了对象，而在ExtJS框架中，代码全在客户端，势必就出现了透过网络来加载数据需要，而我认为，Store就是对通过网络来加载数据的过程的一个抽象，Store依赖于Model，通过关联的Model对象来获知如何将取回的数据对象化，以方便View展现，所以View是依赖Store对象的；（这里岔开一点，感觉这个Store的设计理念或许可以借鉴，由于某些原因，我们在使用PHP框架的时候，不能让Model直接连接DB，是不是也可以把数据取回最终拼接成Model对象的这个过程给抽象化成类似ExtJS中Store的这套机制呢？）</p>
<p>6. View就纯粹是一个界面组件，或者说窗体控件的集合，通过Store来加载数据并且展现到界面上，界面控件的响应都写在Controller里面，View对Controller的存在全无所知，也没有代码上的依赖；</p>
<p>总结一下，感觉这套系统的好处是在于，将View和Model都给抽象了出来，以至于它们可以更加好地被复用，做好一个面板，所有的地方都可以调用，而真正业务逻辑又被很好的封装在了Controller里面，这样也便于去模块化地开发系统，基本感觉上，是一套非常优秀的框架，由于我对ExtJS 3系列版本，没有任何经验，也就没法做出其相对于先前版本是否有质的飞跃的判断，通过仔细的挖掘，我发现其易用性上确实比我原来想象的要好，开发人员可能没太多必要去纠结于内部原理，只要理解到跟我现在差不多的样子，就可以快速上手去做一些东西出来，当然还是必须看着文档按图索骥的，嘿嘿:)</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="MVC就是个选择题" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fmvc-chose-where-to-put-your-code.htm&from=http%3A%2F%2Fsexywp.com%2Fextjs-4-mvc.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">MVC就是个选择题</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="MVC最佳实践" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fmvc-best-practice.htm&from=http%3A%2F%2Fsexywp.com%2Fextjs-4-mvc.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">MVC最佳实践</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Yii框架的Log系统的分析" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fhow-to-use-log-in-yii-framework.htm&from=http%3A%2F%2Fsexywp.com%2Fextjs-4-mvc.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9184865.jpg" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Yii框架的Log系统的分析</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Google可以搜索Twitter的内容了" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fgoogle-search-twitter-content.htm&from=http%3A%2F%2Fsexywp.com%2Fextjs-4-mvc.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/19/13235107.jpg" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Google可以搜索Twitter的内容了</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Join PayingPost and Earn Money Now!" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fsign-up-payingpost.htm&from=http%3A%2F%2Fsexywp.com%2Fextjs-4-mvc.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/08/12/22263808.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Join PayingPost and Earn Money Now!</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/analytics" title="analytics" rel="tag">analytics</a>, <a href="http://sexywp.com/tags/development" title="development" rel="tag">development</a>, <a href="http://sexywp.com/tags/extjs-2" title="extjs" rel="tag">extjs</a>, <a href="http://sexywp.com/tags/mvc" title="MVC" rel="tag">MVC</a>, <a href="http://sexywp.com/tags/yii-2" title="yii" rel="tag">yii</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/extjs-4-mvc.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VIM常用小窍门收集</title>
		<link>http://sexywp.com/vim-tricks-collections.htm</link>
		<comments>http://sexywp.com/vim-tricks-collections.htm#comments</comments>
		<pubDate>Tue, 14 Jun 2011 14:31:30 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[工作相关]]></category>
		<category><![CDATA[心得体会]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[usage]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://sexywp.com/?p=440</guid>
		<description><![CDATA[vim应该是现在世界上最流行的编辑器，没有之一。就算你千般百般地不喜欢它，掌握它也成了一件必须的事情了。因为日后你如果做程序员，在非Win系列的服务器上搞开发，vim绝对是无法避免的。你日常能接触到的server，emacs可能没装，但是vi不可能没装，就这样。

特意开辟这个文章，用于收藏一些工作中常用的操作，主要有这么几个原则：



<span class="readmore"><a href="http://sexywp.com/vim-tricks-collections.htm" title="VIM常用小窍门收集">Keep Reading --- 615 words totally</a></span><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fthe-absolute-bare-minimum-vimrc.htm&from=http%3A%2F%2Fsexywp.com%2Fvim-tricks-collections.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Vim最低配置单</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Flinux-commands-used-when-working.htm&from=http%3A%2F%2Fsexywp.com%2Fvim-tricks-collections.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">工作中常用的Linux命令集锦</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fmac-os-x-ssh-key-pair-login-linux.htm&from=http%3A%2F%2Fsexywp.com%2Fvim-tricks-collections.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Mac OS X上如何实现到Linux主机的ssh免登陆</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fword2007-doesnot-show-pics.htm&from=http%3A%2F%2Fsexywp.com%2Fvim-tricks-collections.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">[Tips]Word2007中看不到图片</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm&from=http%3A%2F%2Fsexywp.com%2Fvim-tricks-collections.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">【边学边用】PHP5函数参数的按引用传递</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>vim应该是现在世界上最流行的编辑器，没有之一。就算你千般百般地不喜欢它，掌握它也成了一件必须的事情了。因为日后你如果做程序员，在非Win系列的服务器上搞开发，vim绝对是无法避免的。你日常能接触到的server，emacs可能没装，但是vi不可能没装，就这样。</p>
<p>特意开辟这个文章，用于收藏一些工作中常用的操作，主要有这么几个原则：</p>
<ol>
<li>非常有用</li>
<li>不常用</li>
<li>每次用都想不起来应该怎么用</li>
</ol>
<p>不知道大家是不是经常跟我一样有这种感受呢，我会把我遇到的这类操作，都详细写在这里。</p>
<h2>将配置文件中的指定列前面加上注释符号</h2>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">#fastcgi.conf</li>
<li>fastcgi_param&nbsp; GATEWAY_INTERFACE&nbsp; CGI/1.1;</li>
<li>fastcgi_param&nbsp; SERVER_SOFTWARE&nbsp; &nbsp; nginx;</li>
<li>fastcgi_param&nbsp; QUERY_STRING&nbsp; &nbsp; &nbsp; &nbsp;$query_string;</li>
<li>fastcgi_param&nbsp; REQUEST_METHOD&nbsp; &nbsp; &nbsp;$request_method;</li>
<li>fastcgi_param&nbsp; CONTENT_TYPE&nbsp; &nbsp; &nbsp; &nbsp;$content_type;</li>
<li>fastcgi_param&nbsp; CONTENT_LENGTH&nbsp; &nbsp; &nbsp;$content_length;</li>
<li>fastcgi_param&nbsp; SCRIPT_FILENAME&nbsp; &nbsp; $document_root$fastcgi_script_name;</li>
<li>fastcgi_param&nbsp; SCRIPT_NAME&nbsp; &nbsp; &nbsp; &nbsp; $fastcgi_script_name;</li>
<li>fastcgi_param&nbsp; REQUEST_URI&nbsp; &nbsp; &nbsp; &nbsp; $request_uri;</li>
<li>fastcgi_param&nbsp; DOCUMENT_URI&nbsp; &nbsp; &nbsp; &nbsp;$document_uri;</li>
<li>fastcgi_param&nbsp; DOCUMENT_ROOT&nbsp; &nbsp; &nbsp; $document_root;</li></ol></div>
<p>如上代码是一个很常见的配置文件，我现在要给第2-12行前面都加上一个#号，注释掉他们，在EmEditor里面这个事情无敌简单的，但是到了vi里面，你是不是总也想不起来应该怎么弄？</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">:2,12s/^/#/g</li></ol></div>
<p>解释一下，【2,12】在vi中叫range，看帮助的时候，如果看到range，这就是一种写法，表明第2行到12行。<br />
还有一种写法：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">:s/^/#/g 11</li></ol></div>
<p>将光标移动到第二行，然后执行上面的命令，后面的【11】代表，执行这个命令，重复11次。这里一直没解释里面那个至关重要的乱码串，那个就是替换的命令了。下次再说。</p>
<h2>删除的时候使用f和t</h2>
<p>删除是vim里面非常常用的功能，一个一个字幕删除，用x，可以代替del用。整行删除，dd，应该都会了。删除一个单词，用dw。这些都是简单提一下，我主要想两个很好用的功能，就是f和t。</p>
<p>f的本意是行查找，fa，就是从光标当前位置开始，在本行中，找到第一个字母a，和d结合起来以后，就非常方便了，比如：</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Blue;">&lt;?php</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">test_php</span><span style="color: Olive;">(</span><span style="color: #00008b;">$a</span><span style="color: Gray;">,</span><span style="color: #00008b;">$b</span><span style="color: Gray;">,</span><span style="color: #00008b;">$c</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp;</span><span style="color: Green;">return</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">true</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li></ol></div></div>
<p>在这个代码里，你想删掉第一个参数，可以把光标放在(后面的第一个$上，然后按&#8221;df,&#8221;，就可以把$a连同后面的逗号都删掉，非常方便。当然了，你可以发挥一下，&#8221;d2f,&#8221;这个按键序列就是把$a和$b都删掉了，但是呢，用数字这种东西，在实际操作中，我感觉大脑经常反应不过来，需要思考，不实用。</p>
<p>在来说一下t，t这个东西，跟f非常像，区别就是t把找光标放到找到的那个字符前面一个位子，比如上面那个例子，我把光标放在第一个$上，然后按下&#8221;dt)&#8221;这个序列，可以把函数的3个参数都删掉，但是却不会删掉括号，非常舒服，在括号里删东西，我经常用这个功能。</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fthe-absolute-bare-minimum-vimrc.htm&from=http%3A%2F%2Fsexywp.com%2Fvim-tricks-collections.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Vim最低配置单</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Flinux-commands-used-when-working.htm&from=http%3A%2F%2Fsexywp.com%2Fvim-tricks-collections.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">工作中常用的Linux命令集锦</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fmac-os-x-ssh-key-pair-login-linux.htm&from=http%3A%2F%2Fsexywp.com%2Fvim-tricks-collections.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Mac OS X上如何实现到Linux主机的ssh免登陆</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fword2007-doesnot-show-pics.htm&from=http%3A%2F%2Fsexywp.com%2Fvim-tricks-collections.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">[Tips]Word2007中看不到图片</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm&from=http%3A%2F%2Fsexywp.com%2Fvim-tricks-collections.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">【边学边用】PHP5函数参数的按引用传递</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/tips" title="tips" rel="tag">tips</a>, <a href="http://sexywp.com/tags/tricks" title="tricks" rel="tag">tricks</a>, <a href="http://sexywp.com/tags/usage" title="usage" rel="tag">usage</a>, <a href="http://sexywp.com/tags/vim" title="vim" rel="tag">vim</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/vim-tricks-collections.htm/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>给SVN客户端配置代理服务器</title>
		<link>http://sexywp.com/use-proxy-in-ur-svn-client.htm</link>
		<comments>http://sexywp.com/use-proxy-in-ur-svn-client.htm#comments</comments>
		<pubDate>Mon, 13 Jun 2011 13:39:47 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[小窍门]]></category>
		<category><![CDATA[工作相关]]></category>
		<category><![CDATA[心得体会]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://sexywp.com/?p=439</guid>
		<description><![CDATA[最常见的SVN客户端其实是TortoiseSVN，我一直叫它作乌龟SVN。上班以后，我在办公室使用SVN连接非办公网络的服务器，发现无法连接，原来，是因为大多数办公网络都设置了防火墙，要连接外网的服务器，必须配置代理。如果使用的是TortoiseSVN，那么“右键”-》“Settings”-》“Networking”，就可以找到设置代理的地方：



我自己经常使用的是另一款SVN客户端，不知道国内有多少用户，总之我也提一下吧，下载的网站是这里：http://www.collab.net/，这家公司是SVN的幕后支持公司，他们开发基于命令行的各种操作系统的客户端，基于命令行，所以就非常的轻巧，最关键是装好以后，可以和NetBeans无缝集成，也不会弄一堆花花绿绿的图标在资源管理器里面，让你看了红色惊叹号凭空焦虑。

<span class="readmore"><a href="http://sexywp.com/use-proxy-in-ur-svn-client.htm" title="给SVN客户端配置代理服务器">Keep Reading --- 536 words totally</a></span><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fhow-to-make-a-easy-svn-server.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-proxy-in-ur-svn-client.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">在WinXP上搭建自己的SVN服务器</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Flinux-commands-used-when-working.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-proxy-in-ur-svn-client.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">工作中常用的Linux命令集锦</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fvim-tricks-collections.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-proxy-in-ur-svn-client.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">VIM常用小窍门收集</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fprocess-oriented-and-object-oriented-design.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-proxy-in-ur-svn-client.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">面向过程与面向对象</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fhow-to-use-log-in-yii-framework.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-proxy-in-ur-svn-client.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Yii框架的Log系统的分析</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>最常见的SVN客户端其实是TortoiseSVN，我一直叫它作乌龟SVN。上班以后，我在办公室使用SVN连接非办公网络的服务器，发现无法连接，原来，是因为大多数办公网络都设置了防火墙，要连接外网的服务器，必须配置代理。如果使用的是TortoiseSVN，那么“右键”-》“Settings”-》“Networking”，就可以找到设置代理的地方：</p>
<p><img src="http://niff.home.xs4all.nl/stuff/tortoiseproxy.png" alt="set proxy in tortoise svn" /></p>
<p>我自己经常使用的是另一款SVN客户端，不知道国内有多少用户，总之我也提一下吧，下载的网站是这里：http://www.collab.net/，这家公司是SVN的幕后支持公司，他们开发基于命令行的各种操作系统的客户端，基于命令行，所以就非常的轻巧，最关键是装好以后，可以和NetBeans无缝集成，也不会弄一堆花花绿绿的图标在资源管理器里面，让你看了红色惊叹号凭空焦虑。</p>
<p>给这个命令行客户端设置代理有点纠结，看不明白的童鞋，自动忽略好了。首先打开CMD，然后键入命令echo %APPDATA%，得到的结果，就是你的配置所在的根目录，进入那个目录，然后进入Subversion子目录，你会看到两个配置文件，一个叫config，一个叫servers，用写字板编辑那个servers的配置文件：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">[global]</li>
<li># http-proxy-exceptions = *.exception.com, www.internal-site.org</li>
<li>http-proxy-host = defaultproxy.whatever.com</li>
<li>http-proxy-port = 7000</li>
<li>http-proxy-username = defaultusername</li>
<li>http-proxy-password = defaultpassword</li></ol></div>
<p>配置好后，就可以实现给SVN客户端挂上了代理，如果只想给特定的域挂代理，就使用另一个section来配置代理：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">[groups]</li>
<li>group1 = *.googlecode.com</li>
<li># othergroup = repository.blarggitywhoomph.com</li>
<li># thirdgroup = *.example.com</li>
<li>&nbsp;</li>
<li>### Information for the first group:</li>
<li>[group1]</li>
<li>http-proxy-host = proxy.myoffice.com</li>
<li>http-proxy-port = 8080</li>
<li># http-proxy-username = blah</li>
<li># http-proxy-password = doubleblah</li>
<li># http-timeout = 60</li></ol></div>
<p>如上只是我的配置的一个节选，是我给googlecode这个域配置了一个代理。</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fhow-to-make-a-easy-svn-server.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-proxy-in-ur-svn-client.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">在WinXP上搭建自己的SVN服务器</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Flinux-commands-used-when-working.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-proxy-in-ur-svn-client.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">工作中常用的Linux命令集锦</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fvim-tricks-collections.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-proxy-in-ur-svn-client.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">VIM常用小窍门收集</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fprocess-oriented-and-object-oriented-design.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-proxy-in-ur-svn-client.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">面向过程与面向对象</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fhow-to-use-log-in-yii-framework.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-proxy-in-ur-svn-client.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Yii框架的Log系统的分析</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/proxy" title="proxy" rel="tag">proxy</a>, <a href="http://sexywp.com/tags/subversion" title="subversion" rel="tag">subversion</a>, <a href="http://sexywp.com/tags/svn" title="svn" rel="tag">svn</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/use-proxy-in-ur-svn-client.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>工作中常用的Linux命令集锦</title>
		<link>http://sexywp.com/linux-commands-used-when-working.htm</link>
		<comments>http://sexywp.com/linux-commands-used-when-working.htm#comments</comments>
		<pubDate>Tue, 12 Apr 2011 12:37:33 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[工作相关]]></category>
		<category><![CDATA[心得体会]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[usage]]></category>

		<guid isPermaLink="false">http://sexywp.com/?p=419</guid>
		<description><![CDATA[tcpdump —— 打印出通过网口流入流出的数据内容，用于网络协议调试

tcpdump就是大家嘴里常说的抓包工具，在linux命令行下，使用tcpdump，可以查看服务器特定端口进出的数据包内容。

tcpdump -X -s0 -i any udp port 12009

<span class="readmore"><a href="http://sexywp.com/linux-commands-used-when-working.htm" title="工作中常用的Linux命令集锦">Keep Reading --- 1186 words totally</a></span><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fmac-os-x-ssh-key-pair-login-linux.htm&from=http%3A%2F%2Fsexywp.com%2Flinux-commands-used-when-working.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Mac OS X上如何实现到Linux主机的ssh免登陆</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fvim-tricks-collections.htm&from=http%3A%2F%2Fsexywp.com%2Flinux-commands-used-when-working.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">VIM常用小窍门收集</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fword2007-doesnot-show-pics.htm&from=http%3A%2F%2Fsexywp.com%2Flinux-commands-used-when-working.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">[Tips]Word2007中看不到图片</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fnetbeans-plugins-i-used.htm&from=http%3A%2F%2Fsexywp.com%2Flinux-commands-used-when-working.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">NetBeans 中我选用的插件</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fprocess-oriented-and-object-oriented-design.htm&from=http%3A%2F%2Fsexywp.com%2Flinux-commands-used-when-working.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">面向过程与面向对象</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<h3>tcpdump —— 打印出通过网口流入流出的数据内容，用于网络协议调试</h3>
<p>tcpdump就是大家嘴里常说的抓包工具，在linux命令行下，使用tcpdump，可以查看服务器特定端口进出的数据包内容。<br />
<code>tcpdump -X -s0 -i any udp port 12009</code><span id="more-419"></span><br />
上述命令是我在工作中常用的一组参数组合，其含义如下：</p>
<ul>
<li>-X 将每个包打印成16进制形式和ASCII形式，调试新协议的时候非常方便</li>
<li>-sN 每个包显示的（截断）字节数，N代表字节数，填0代表64K，为UDP包最大长度，实际实践中UDP包长1500字节左右，如果调试的协议只关心包头，一般查看前128个字节即可，可以视情况而选择。</li>
<li>-i 代表interface，可以认为是网卡，any代表任意，也可以填eth0，eth1，代表以太网口</li>
<li>udp port 12009是表达式，例子的含义就是UDP协议，12009端口。</li>
</ul>
<p><code>tcpdump [ -adeflnNOpqStvx ] [ -c 数量 ] [ -F 文件名 ][ -i 网络接口 ] [ -r 文件名] [ -s snaplen ][ -T 类型 ] [ -w 文件名 ] [表达式 ]</code></p>
<p>如上是tcpdump命令的完整格式，具体每个参数的含义，可以参看linux的man。</p>
<p>这里简单谈谈最后的那个“表达式”，这个表达式的写法是非常灵活的，使得tcpdump像一个可自由编程的调试工具一样，强大异常。这里可以把表达式理解成是一种编程语言的语句。</p>
<ol>
<li>表达式 = 语句 语句 语句 ……</li>
<li>语句 = 修饰符 | 修饰符 内容</li>
</ol>
<p>不知道我上面的描述方式，是不是说清楚了表达式的结构，表达式是一个又一个原语（primitives）组成的，每个原语又是由修饰符和数据组成。数据可以数字或者id或者ip或者range等。</p>
<p>修饰符有很多种：</p>
<ol>
<li>类型&#8211;可以是host（后面跟主机名），net（后面跟ip地址），port（和面跟端口号），如果不指定，默认是host</li>
<li>方向&#8211;可以是src，src or dst，src and dst，dst，主要是源端还是目的端，如果不指定，默认是src or dst</li>
<li>协议&#8211;就比较多了，常用的就udp和tcp，其他的可以看参考</li>
</ol>
<p>现在再来看看我给的例子，udp port 12009，表示使用UDP协议的，通过12009端口的（进入和出去的）包都显示出来。</p>
<p>tcpdump这个工具还是比较难以记住的，Charels觉得还是要注意理解这个命令的功能和原理，然后在用到的时候，才能快速的找到准确的用法。</p>
<h3>netstat —— 打印网络连接，路由表，网络数据统计等功能</h3>
<p>netstat是Linux服务器上最常用的命令之一，一般我总是用这个命令来诊断一些问题：mysql是否已经成功启动？web server是否已经成功启动？哪些进程在侦听哪些端口，建立了哪些连接？<br />
<code>netstat -npl</code><br />
这是我最常用的参数组合，n代表使用数字，哪个进程在哪个IP上侦听哪个端口，你看到的结果列表里，是192.168.26.128:3306这种形式的，这个例子里是mysql正常启动的状态，一般mysql启动后，会有一个进程侦听在3306端口上，如果不是用n参数，netstat会试图找出主机和程序的名字，会显示成localhost:mysql类似这样。<br />
p代表program，也即程序，到底是哪个程序在侦听端口呢？这个进程的id是多少？就是用这个参数来显示的。所以，np一般一起用，前面用n现实IP，后面用p显示程序的名字。<br />
l代表listen，代表让命令只列出正在侦听端口的进程，对于那些不活跃的则不显示，与l相对应的参数是a，代表all，表示列出所有的socket，不管是在侦听还是没在侦听的。<br />
其他的参数还有很多，比如i可以现实所有的网卡，s可以现实所有包的统计，但是因为使用场景较少，我就不介绍了，大家可以自己去看man，不爽看woman也行:)</p>
<h3>lsof —— 待续</h3>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fmac-os-x-ssh-key-pair-login-linux.htm&from=http%3A%2F%2Fsexywp.com%2Flinux-commands-used-when-working.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Mac OS X上如何实现到Linux主机的ssh免登陆</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fvim-tricks-collections.htm&from=http%3A%2F%2Fsexywp.com%2Flinux-commands-used-when-working.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">VIM常用小窍门收集</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fword2007-doesnot-show-pics.htm&from=http%3A%2F%2Fsexywp.com%2Flinux-commands-used-when-working.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">[Tips]Word2007中看不到图片</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fnetbeans-plugins-i-used.htm&from=http%3A%2F%2Fsexywp.com%2Flinux-commands-used-when-working.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">NetBeans 中我选用的插件</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fprocess-oriented-and-object-oriented-design.htm&from=http%3A%2F%2Fsexywp.com%2Flinux-commands-used-when-working.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">面向过程与面向对象</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/command" title="command" rel="tag">command</a>, <a href="http://sexywp.com/tags/linux" title="Linux" rel="tag">Linux</a>, <a href="http://sexywp.com/tags/tips" title="tips" rel="tag">tips</a>, <a href="http://sexywp.com/tags/usage" title="usage" rel="tag">usage</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/linux-commands-used-when-working.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Yii框架的Log系统的分析</title>
		<link>http://sexywp.com/how-to-use-log-in-yii-framework.htm</link>
		<comments>http://sexywp.com/how-to-use-log-in-yii-framework.htm#comments</comments>
		<pubDate>Wed, 30 Mar 2011 17:00:21 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Yii]]></category>
		<category><![CDATA[工作相关]]></category>
		<category><![CDATA[心得体会]]></category>
		<category><![CDATA[日　　记]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[source code]]></category>
		<category><![CDATA[yii]]></category>

		<guid isPermaLink="false">http://sexywp.com/?p=418</guid>
		<description><![CDATA[昨天阅读了Yii框架中log部分的源代码，框架提供了灵活、强大的log功能，如果不是非常特殊的需求，框架中自带的类就已经能够满足一般的应用的需求了。实现log功能的源代码被存放在 framework/logging 目录下，这个目录下的代码都包含在包system.logging中。本文简要介绍一下我昨天阅读代码的所得。





<span class="readmore"><a href="http://sexywp.com/how-to-use-log-in-yii-framework.htm" title="Yii框架的Log系统的分析">Keep Reading --- 1988 words totally</a></span><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="视频教程：使用Yii框架开发Blog" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fvideo-guide-to-use-yii-framework.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-use-log-in-yii-framework.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9170385.jpg" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">视频教程：使用Yii框架开发Blog</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Yii框架中验证器的allowEmpty属性" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fyii-validator-allwoempty-property.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-use-log-in-yii-framework.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Yii框架中验证器的allowEmpty属性</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Yii框架base包代码分析" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fyii-package-base-source-code-analysis.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-use-log-in-yii-framework.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/11/20/11182613.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Yii框架base包代码分析</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用Gii时出现403错误" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Ferror-403-occured-when-use-gii.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-use-log-in-yii-framework.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用Gii时出现403错误</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="面向过程与面向对象" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fprocess-oriented-and-object-oriented-design.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-use-log-in-yii-framework.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">面向过程与面向对象</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>昨天阅读了Yii框架中log部分的源代码，框架提供了灵活、强大的log功能，如果不是非常特殊的需求，框架中自带的类就已经能够满足一般的应用的需求了。实现log功能的源代码被存放在 <a href="http://sexywp.com/tags/framework" class="st_tag internal_tag" rel="tag" title="标签 framework 下的日志">framework</a>/logging 目录下，这个目录下的代码都包含在包system.logging中。本文简要介绍一下我昨天阅读代码的所得。<span id="more-418"></span></p>
<table style="width:auto;">
<tr>
<td><a href="https://picasaweb.google.com/lh/photo/o9iXH2bPs0j6RS1aWaAt5A?feat=embedwebsite"><img src="https://lh5.googleusercontent.com/_QYicOeu89Bk/TZNMKYScKKI/AAAAAAAAB3E/ardNZrMAYFM/s640/class-graph.jpg" height="471" width="640" /></a></td>
</tr>
<tr>
<td style="font-family:arial,sans-serif; font-size:11px; text-align:right"><a href="https://picasaweb.google.com/TangChao.ZJU/Illustration?feat=embedwebsite">system.logging 包类结构图</a></td>
</tr>
</table>
<p>首先，来看一下这个图，这是Charles昨夜工作的结晶，研究了logging目录下一共九个文件中的类的关系。YiiBase，<a href="http://sexywp.com/tags/yii-2" class="st_tag internal_tag" rel="tag" title="标签 yii 下的日志">Yii</a>，CWebApplication不属于logging目录，但是为了说明这些类如何发生作用，也放在了这种图里。我的初衷，是要画一张标准的UML图的，无奈于本科的知识都还给老师了，所以这个图只能算是个四不像，大家凑合看一下，后面我会给自己补补课，后续的文章画得图会趋于规范的。</p>
<p>言归正传，左下角的类CLogger，是在开发过程中，打log时候，真正调用的类，这个类作为所有应用最最基础的组件，被包含在了YiiBase中，任何时候，在代码中调用Yii::getLogger()函数，会得到一个CLogger类的实例，这里用的是一个单件模式（Singleton）。打印log，只要调用其log()方法即可，这个方法有三个参数，第一个是log的内容，第二个是级别（warning，debug，fatal等），第三个category，可以叫类别，也可以视作是一种标识符，可以用于log的过滤。</p>
<div class="hl-surround"><div class="hl-main"><span style="color: Blue;">Yii</span><span style="color: Gray;">::</span><span style="color: Blue;">getLogger</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">log</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">here is a debug info.</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">debug</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">app.siteController</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></div></div>
<p>上面的代码片段给出了一个打印log的范例，任何时候想打log，只要这样写就好。从上面的代码片段中，我们看到，log系统的调用接口是极其简单的。接下来分析一下大家非常关心的，log到底会被怎么处理的问题。</p>
<p>在框架中这个log系统里，负责打log，和负责记录log的是两个对象，他们被很好的解耦合了。CLogger扮演了一个专门生产log的角色，其任务就是将用户使用log()函数记录的log放到一个数组里，可以认为是一个内存buffer，长度可配置。在buffer满了的时候，会激发flush（如果配置了autoFlush）的话，flush就是冲掉的意思，如果内存buffer满了，则清空之，继续接受log信息。在清空log buffer之前，这个类对象会触发一个事件，就是onFlush事件，后续其他的类hook到这个onFlush事件上，就可以在log信息被清空之前，有所动作了。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: Green;">public</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">log</span><span style="color: Olive;">(</span><span style="color: #00008b;">$message</span><span style="color: Gray;">,</span><span style="color: #00008b;">$level</span><span style="color: Gray;">=</span><span style="color: #8b0000;">'</span><span style="color: Red;">info</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,</span><span style="color: #00008b;">$category</span><span style="color: Gray;">=</span><span style="color: #8b0000;">'</span><span style="color: Red;">application</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Olive;">{</span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">$this-&gt;_logs就是一个数组，也即存放log信息的内存缓冲，默认10000行</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">_logs</span><span style="color: Olive;">[</span><span style="color: Olive;">]</span><span style="color: Gray;">=</span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: #00008b;">$message</span><span style="color: Gray;">,</span><span style="color: #00008b;">$level</span><span style="color: Gray;">,</span><span style="color: #00008b;">$category</span><span style="color: Gray;">,</span><span style="color: Blue;">microtime</span><span style="color: Olive;">(</span><span style="color: Green;">true</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">_logCount</span><span style="color: Gray;">++;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Olive;">(</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">autoFlush</span><span style="color: Gray;">&gt;</span><span style="color: Maroon;">0</span><span style="color: Gray;"> &amp;&amp; </span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">_logCount</span><span style="color: Gray;">&gt;=</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">autoFlush</span><span style="color: Olive;">)</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">flush</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">缓冲满了后，会调用flush</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp; </span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Green;">public</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">flush</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">onFlush</span><span style="color: Olive;">(</span><span style="color: Green;">new</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">CEvent</span><span style="color: Olive;">(</span><span style="color: #00008b;">$this</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">激发onFlush事件</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">_logs</span><span style="color: Gray;">=</span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">清空缓冲</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">_logCount</span><span style="color: Gray;">=</span><span style="color: Maroon;">0</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>这是一个生产者与消费者的故事，以上讲述的是生产者的故事。接下来，讲消费者的故事。CLogger已经在内存中生产了log，那么接下来就要来收集，分析，处理这些log，该记录的记录，该抛弃的抛弃，该报警的报警。当然，你可以不给系统提供消费者，那些log产生了，然后消失了，基本不会带来什么负载和泄露，轻轻松松。</p>
<p>log的生产者是系统中必然存在的，但是log的消费者不是，是通过配置文件配置到系统中的，打开位于/protected/config/main.php的配置文件，在components段，我们可以看到关于log组件的配置，如下所示：</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: #8b0000;">'</span><span style="color: Red;">log</span><span style="color: #8b0000;">'</span><span style="color: Gray;">=&gt;</span><span style="color: Green;">array</span><span style="color: Olive;">(</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #8b0000;">'</span><span style="color: Red;">class</span><span style="color: #8b0000;">'</span><span style="color: Gray;">=&gt;</span><span style="color: #8b0000;">'</span><span style="color: Red;">CLogRouter</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #8b0000;">'</span><span style="color: Red;">routes</span><span style="color: #8b0000;">'</span><span style="color: Gray;">=&gt;</span><span style="color: Green;">array</span><span style="color: Olive;">(</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">array</span><span style="color: Olive;">(</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #8b0000;">'</span><span style="color: Red;">class</span><span style="color: #8b0000;">'</span><span style="color: Gray;">=&gt;</span><span style="color: #8b0000;">'</span><span style="color: Red;">CFileLogRoute</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #8b0000;">'</span><span style="color: Red;">levels</span><span style="color: #8b0000;">'</span><span style="color: Gray;">=&gt;</span><span style="color: #8b0000;">'</span><span style="color: Red;">error, warning</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">)</span><span style="color: Gray;">,</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;"> uncomment the following to show log messages on web pages</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #ffa500;">/*</span></li>
<li><span style="color: #ffa500;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; array(</span></li>
<li><span style="color: #ffa500;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'class'=&gt;'CWebLogRoute',</span></li>
<li><span style="color: #ffa500;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ),</span></li>
<li><span style="color: #ffa500;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #ffa500;">*/</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">)</span><span style="color: Gray;">,</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">)</span><span style="color: Gray;">,</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>负责采集处理log的真正对象，是一组以Route结尾的类，在上面类图中，位于右上角的那5个类。它们各有个的功能，发邮件的，写文件的，写Db的等等。前面也提了，对于一堆log，可能各自要使用不同的方法处理，比如debug信息抛弃，info信息记录在文件，而fatal信息发邮件给管理员，一个系统中很可能有这样那样的需求。所以，被以组件形式装进应用中的，并不是Route，而是类图中叫CLogRouter的对象。</p>
<p>对log的各种处理方法，都继承自一个叫CLogRoute的抽象类，提供了统一的调用接口，CLogRouter就是这些route的管理者，它主要负责的就是在onFlush事件发生的时候，把CLogger生产的log都接过来，然后，逐一地交付给自己旗下的Route们，分别处理。从上面的配置信息里，我们可以看到，LogRouter管理多少个Route也是通过配置文件配置的，也即route是router所依赖的组件。在具体开发过程中，你可以只配置一个，也可以配置一群。这种行为特征，真的有点像路由，怪不得叫router和route，我猜就这么个解释。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: Green;">public</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">collectLogs</span><span style="color: Olive;">(</span><span style="color: #00008b;">$event</span><span style="color: Olive;">)</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$logger</span><span style="color: Gray;">=</span><span style="color: Blue;">Yii</span><span style="color: Gray;">::</span><span style="color: Blue;">getLogger</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">foreach</span><span style="color: Olive;">(</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">_routes</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">as</span><span style="color: Gray;"> </span><span style="color: #00008b;">$route</span><span style="color: Olive;">)</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">{</span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">Router向每个route分发log，请求处理</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Olive;">(</span><span style="color: #00008b;">$route</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">enabled</span><span style="color: Olive;">)</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$route</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">collectLogs</span><span style="color: Olive;">(</span><span style="color: #00008b;">$logger</span><span style="color: Gray;">,</span><span style="color: Green;">false</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp; </span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Green;">public</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">processLogs</span><span style="color: Olive;">(</span><span style="color: #00008b;">$event</span><span style="color: Olive;">)</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$logger</span><span style="color: Gray;">=</span><span style="color: Blue;">Yii</span><span style="color: Gray;">::</span><span style="color: Blue;">getLogger</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">foreach</span><span style="color: Olive;">(</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">_routes</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">as</span><span style="color: Gray;"> </span><span style="color: #00008b;">$route</span><span style="color: Olive;">)</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">{</span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">Router向每个route分发log，请求处理</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Olive;">(</span><span style="color: #00008b;">$route</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">enabled</span><span style="color: Olive;">)</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$route</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">collectLogs</span><span style="color: Olive;">(</span><span style="color: #00008b;">$logger</span><span style="color: Gray;">,</span><span style="color: Green;">true</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>在操作实践中，我们完全可以自己继承CLogRoute，实现collectLogs方法，可以开发譬如名为NetLogRoute的类，将log从网络端口上以UDP包或者通过TCP连接形式发送到网络上专门的log服务器中，也可以开发名为MobileLogRoute的类，用来给管理员发送手机报警短信。</p>
<p>上面一直没有介绍到的Filter，其作用其实可以顾名思义，就是在log处理的时候，过滤用的，可以根据前文提到的category参数来过滤，也可以根据log等级类过滤，等等等等。Filter也是通过参数配置的形式被插入到route中的，完全可以创建自己特有的filter通过配置来替换默认filter，可以说，将灵活性发挥到了极致。不过，灵活还是有牺牲的，比如我就觉得，如果一个router下面挂上N个route之后，每个route都采用特定的filter，则会造成同一批log（10000条）被过滤的N遍。所以，比较好的模式，可能还是一个router，下面一个route，然后可以选择用或者不用filter，挂多个虽然理论可行，但是从实际代码来看，可能有一定性能损耗。</p>
<p>好了，终于啰嗦完了，最后问个问题，整个logging系统的这种结构，到底是哪一种设计模式呢？欢迎交流哈～</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="视频教程：使用Yii框架开发Blog" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fvideo-guide-to-use-yii-framework.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-use-log-in-yii-framework.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9170385.jpg" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">视频教程：使用Yii框架开发Blog</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Yii框架中验证器的allowEmpty属性" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fyii-validator-allwoempty-property.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-use-log-in-yii-framework.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Yii框架中验证器的allowEmpty属性</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Yii框架base包代码分析" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fyii-package-base-source-code-analysis.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-use-log-in-yii-framework.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/11/20/11182613.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Yii框架base包代码分析</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用Gii时出现403错误" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Ferror-403-occured-when-use-gii.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-use-log-in-yii-framework.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用Gii时出现403错误</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="面向过程与面向对象" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fprocess-oriented-and-object-oriented-design.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-use-log-in-yii-framework.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">面向过程与面向对象</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/framework" title="framework" rel="tag">framework</a>, <a href="http://sexywp.com/tags/source-code" title="source code" rel="tag">source code</a>, <a href="http://sexywp.com/tags/yii-2" title="yii" rel="tag">yii</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/how-to-use-log-in-yii-framework.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MVC就是个选择题</title>
		<link>http://sexywp.com/mvc-chose-where-to-put-your-code.htm</link>
		<comments>http://sexywp.com/mvc-chose-where-to-put-your-code.htm#comments</comments>
		<pubDate>Thu, 30 Dec 2010 06:04:28 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[心得体会]]></category>
		<category><![CDATA[design pattern]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://sexywp.com/?p=412</guid>
		<description><![CDATA[由于采用了Web开发框架来开发项目，所以我首次在真正的项目中采用MVC的开发模式。随着项目的不断深入，我也在不断反思，MVC设计模式到底给项目带来了什么？成倍的开发时间？复杂无比的目录结构？铺天盖地的文件数量？听起来都很难听对吗，但是确实如此。那么MVC所许诺的那些好处呢？清晰的代码结构，易于维护，易于扩展？真有吗？

当然，我不是在批判MVC，只是觉得，在使用MVC过程中，还是需要投入更深入的思考，到底怎样才能用好这个设计模式。MVC给我的感觉是，要求使用其的开发者有更高的觉悟，来正确选择存放一段代码的地方。从而实现解耦合，代码复用，和易于维护。为什么说使用MVC会有成倍的开发时间，主要就是因为在开发中，我们需要更多的时间去思考，这些代码放在哪里更合理一些。在MVC框架下代码被切割成一个又一个的小文件，分散在复杂的目录树中，那么到底怎样选择把代码写在哪里呢？这道选择题，并非有看起来那么容易。就我个人感受而言，更多的时候，无论将代码放在哪里都可以正确实现你的逻辑，MVC不是什么神兵利器，并不能通过其模式本身的约束，将开发者导入到一个正确的轨道上，反而会因为开发者本身错误的选择而让MVC自己变得一团糟。所以说，当一个团队确定要在一个项目中引入MVC时候，应该思考一下，每个团队成员是不是真的都有能力驾驭，如果没有对应的能力话，是不是要考虑前期对项目成员进行一定的培训。

<span class="readmore"><a href="http://sexywp.com/mvc-chose-where-to-put-your-code.htm" title="MVC就是个选择题">Keep Reading --- 1444 words totally</a></span><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fmvc-best-practice.htm&from=http%3A%2F%2Fsexywp.com%2Fmvc-chose-where-to-put-your-code.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">MVC最佳实践</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fextjs-4-mvc.htm&from=http%3A%2F%2Fsexywp.com%2Fmvc-chose-where-to-put-your-code.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">ExtJS 4 的MVC</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fprocess-oriented-and-object-oriented-design.htm&from=http%3A%2F%2Fsexywp.com%2Fmvc-chose-where-to-put-your-code.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">面向过程与面向对象</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fhow-to-use-log-in-yii-framework.htm&from=http%3A%2F%2Fsexywp.com%2Fmvc-chose-where-to-put-your-code.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Yii框架的Log系统的分析</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fvim-tricks-collections.htm&from=http%3A%2F%2Fsexywp.com%2Fmvc-chose-where-to-put-your-code.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">VIM常用小窍门收集</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>由于采用了Web开发框架来开发项目，所以我首次在真正的项目中采用MVC的开发模式。随着项目的不断深入，我也在不断反思，MVC设计模式到底给项目带来了什么？成倍的开发时间？复杂无比的目录结构？铺天盖地的文件数量？听起来都很难听对吗，但是确实如此。那么MVC所许诺的那些好处呢？清晰的代码结构，易于维护，易于扩展？真有吗？<span id="more-412"></span></p>
<p>当然，我不是在批判MVC，只是觉得，在使用MVC过程中，还是需要投入更深入的思考，到底怎样才能用好这个设计模式。MVC给我的感觉是，要求使用其的开发者有更高的觉悟，来正确选择存放一段代码的地方。从而实现解耦合，代码复用，和易于维护。为什么说使用MVC会有成倍的开发时间，主要就是因为在开发中，我们需要更多的时间去思考，这些代码放在哪里更合理一些。在MVC框架下代码被切割成一个又一个的小文件，分散在复杂的目录树中，那么到底怎样选择把代码写在哪里呢？这道选择题，并非有看起来那么容易。就我个人感受而言，更多的时候，无论将代码放在哪里都可以正确实现你的逻辑，MVC不是什么神兵利器，并不能通过其模式本身的约束，将开发者导入到一个正确的轨道上，反而会因为开发者本身错误的选择而让MVC自己变得一团糟。所以说，当一个团队确定要在一个项目中引入MVC时候，应该思考一下，每个团队成员是不是真的都有能力驾驭，如果没有对应的能力话，是不是要考虑前期对项目成员进行一定的培训。</p>
<p>可能我说得话很装逼，但是我绝对不敢以一个专家的身份站到这里来说话，我只是一个初学者，我要把我的学习感受说出来。现在回归到MVC上，Controller给我的印象是一个协调者的形象，它知道谁能干什么，然后分配任务，构造哪个对象，初始化哪个视图，是Controller应该决定的事情。Model呢，应该是一个实干家的形象，负责所有肮脏而又细致的事情，所以我在编码实践中，将所有的业务逻辑都塞进Model里面，对Controller，提供一个简单接口，对Views，输出纯数据。View则是一个消费者的形象，给其的数据都是纯粹的，直接显示即可以。以上是我对MVC这道选择题给出的一个答案，当然我不是很确定这样做很对。</p>
<p>我在项目中就看到过这样的代码，将Model做成了一个工具箱，实际上是一个有各种方法的对象，每个方法看起来也提供了简单的调用接口，实际跟Controller配合时候呢，由Controller来操纵功能，安排各个方法被调用的顺序。这等于是由Controller来执行业务逻辑，但是却又对其封装了每个步骤的细节。而我个人倾向于连业务逻辑也对Controller封装。这两种选择各有优劣，而实际上从短期也难看出来谁更胜一筹。甚至，等项目上线后，最终也没法发现哪个做法更优一点。</p>
<p>所以说，MVC真的就是一个选择题。你有多重选择来实现同一个目的。我列举的例子只是九牛一毛，在实际项目开发中，还面临着更多的选择问题。我想，到底怎样交出自己的答案，还是应该在实践过程中不断积累，不断优化。我们只要把握好一些原则，就可以让自己不要偏离航向太远。第一，可维护性，代码逻辑一目了然应该是写代码时候的第一追求，因为看别人的代码是非常痛苦的，甚至最后回头来看自己写过的代码可能都会很痛苦，保持代码一目了然才是最重要的，给别人，给自己节省下时间。第二，可复用性，写内聚度高的代码，减少依赖，判定很简单，我写的这个代码，拷贝到别的项目里，是不是直接就能用，时刻问自己这个问题，就能保持代码的高内聚度。第三，封装变化，这个原则总体来说很难把握住，我自己的体会就是尽可能提供一个强大的接口，如果XXX改变了，那么调用我写的函数是不是格式不变？如果你写的函数，一会儿增加个参数，一会减少个参数，那么所有调用的地方都会跟着变化修改。</p>
<p>就到此为止了，一些愚见，请大家指正。</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fmvc-best-practice.htm&from=http%3A%2F%2Fsexywp.com%2Fmvc-chose-where-to-put-your-code.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">MVC最佳实践</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fextjs-4-mvc.htm&from=http%3A%2F%2Fsexywp.com%2Fmvc-chose-where-to-put-your-code.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">ExtJS 4 的MVC</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fprocess-oriented-and-object-oriented-design.htm&from=http%3A%2F%2Fsexywp.com%2Fmvc-chose-where-to-put-your-code.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">面向过程与面向对象</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fhow-to-use-log-in-yii-framework.htm&from=http%3A%2F%2Fsexywp.com%2Fmvc-chose-where-to-put-your-code.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Yii框架的Log系统的分析</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fsexywp.com%2Fvim-tricks-collections.htm&from=http%3A%2F%2Fsexywp.com%2Fmvc-chose-where-to-put-your-code.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">VIM常用小窍门收集</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/design-pattern" title="design pattern" rel="tag">design pattern</a>, <a href="http://sexywp.com/tags/mvc" title="MVC" rel="tag">MVC</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/mvc-chose-where-to-put-your-code.htm/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

