<?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>貳夢の弦 &#187; PHP</title>
	<atom:link href="http://blog.frost.tw/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.frost.tw</link>
	<description>夢醒之時，驚覺一切都是虛幻。前行吧！迷途者。</description>
	<lastBuildDate>Wed, 26 Oct 2011 13:28:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<atom:link rel='hub' href='http://blog.frost.tw/?pushpress=hub'/>
		<item>
		<title>Hello, Drupal!</title>
		<link>http://blog.frost.tw/site-built/poston-2011-06-14/postid-1212</link>
		<comments>http://blog.frost.tw/site-built/poston-2011-06-14/postid-1212#comments</comments>
		<pubDate>Tue, 14 Jun 2011 11:11:53 +0000</pubDate>
		<dc:creator>蒼時弦や</dc:creator>
				<category><![CDATA[網站架設]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.frost.tw/?p=1212</guid>
		<description><![CDATA[今天在蒐集資料時，陰錯陽差的看到Drupal這個關鍵字。 此時我想起過去使用的經驗，然後還是好奇的再次打開官方網站。 仔細一看，才發現原來Drupal是如此強大的CMS架站機阿！ 在一篇比較WordPress, Drupal, Jamoola 的文章中，我才知道Drupal的彈性。 確實，晚飯前下載了Drupal安裝後，發現彈性真的非常強。 原本我以為WordPress已經非常有彈性了！ 沒想到Drupal的彈性比WordPress更高。 以這個情況來看，我想Drupal對於高度客製化的網站一定是首選。 不過為何WordPress還是被選擇呢？ 因為Drupal真的很難學…… 不過仔細了解他的API部份後，我也覺得這算正常拉！ 畢竟沒有十全十美的程式，要程式做越多，捨棄掉的就是越多的彈性。 我猜Drupal是為了保存這個彈性而捨棄掉了易用性。 不過這也是另一種看法，不過在Drupal的彈性與細節上真的不是WordPress可以比較的！ （個人認為WordPress還是以網誌當其中一個軸，所以在編輯上比較容易） 但我認為WordPress的後台介面比較有親和力！ 因為在使用上很簡潔、清楚，相較之下在Drupal的後台介面，就需要頻繁切換了！ 不過，當我看到Drupal預設的Forum模組後，我才深刻體會到Drupal的高度彈性。 只需要不到十個檔案，就能產生出一個論壇。 在WordPress上會因為與版模相互衝突的關係，而無法使用類似的方式。 （在WordPress使用PostType+迴響，只會讓網誌看起來還是網誌而已，不會有類似論壇的介面呈現出來。） 在Drupal這種以Node為單位的網站和介面架構上，卻讓他輕鬆呈現出來了！ 我想這就是所謂的彈性與易用性的差異吧…… 不過，我認為Drupal開發和使用上都有一定難度，但是高度客製化真的就很適合選用這個了！ 趕緊去寫一個FirstTry Module出來體驗Drupal API提供的高度客製化彈性！<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.htm?url=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2009-11-28%2Fpostid-208&from=http%3A%2F%2Fblog.frost.tw%2Fsite-built%2Fposton-2011-06-14%2Fpostid-1212">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">SEO 與 PHP Blog</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fweb-project%2Fposton-2010-03-03%2Fpostid-431&from=http%3A%2F%2Fblog.frost.tw%2Fsite-built%2Fposton-2011-06-14%2Fpostid-1212">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">DIY一個PHP留言板之規劃</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fweb-project%2Fposton-2010-03-08%2Fpostid-441&from=http%3A%2F%2Fblog.frost.tw%2Fsite-built%2Fposton-2011-06-14%2Fpostid-1212">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">DIY一個PHP留言板之資料存取(四)</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fweb-project%2Fposton-2010-03-04%2Fpostid-433&from=http%3A%2F%2Fblog.frost.tw%2Fsite-built%2Fposton-2011-06-14%2Fpostid-1212">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">DIY一個PHP留言板之資料存取(一)</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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>今天在蒐集資料時，陰錯陽差的看到Drupal這個關鍵字。<br />
此時我想起過去使用的經驗，然後還是好奇的再次打開官方網站。</p>
<p>仔細一看，才發現原來Drupal是如此強大的CMS架站機阿！<br />
在一篇比較WordPress, Drupal, Jamoola 的文章中，我才知道Drupal的彈性。<br />
<span id="more-1212"></span><br />
確實，晚飯前下載了Drupal安裝後，發現彈性真的非常強。<br />
原本我以為WordPress已經非常有彈性了！<br />
沒想到Drupal的彈性比WordPress更高。</p>
<p>以這個情況來看，我想Drupal對於高度客製化的網站一定是首選。<br />
不過為何WordPress還是被選擇呢？</p>
<p>因為Drupal真的很難學……<br />
不過仔細了解他的API部份後，我也覺得這算正常拉！</p>
<p>畢竟沒有十全十美的程式，要程式做越多，捨棄掉的就是越多的彈性。<br />
我猜Drupal是為了保存這個彈性而捨棄掉了易用性。</p>
<p>不過這也是另一種看法，不過在Drupal的彈性與細節上真的不是WordPress可以比較的！<br />
（個人認為WordPress還是以網誌當其中一個軸，所以在編輯上比較容易）<br />
但我認為WordPress的後台介面比較有親和力！<br />
因為在使用上很簡潔、清楚，相較之下在Drupal的後台介面，就需要頻繁切換了！</p>
<p>不過，當我看到Drupal預設的Forum模組後，我才深刻體會到Drupal的高度彈性。<br />
只需要不到十個檔案，就能產生出一個論壇。<br />
在WordPress上會因為與版模相互衝突的關係，而無法使用類似的方式。<br />
（在WordPress使用PostType+迴響，只會讓網誌看起來還是網誌而已，不會有類似論壇的介面呈現出來。）<br />
在Drupal這種以Node為單位的網站和介面架構上，卻讓他輕鬆呈現出來了！</p>
<p>我想這就是所謂的彈性與易用性的差異吧……<br />
不過，我認為Drupal開發和使用上都有一定難度，但是高度客製化真的就很適合選用這個了！</p>
<p>趕緊去寫一個FirstTry Module出來體驗Drupal API提供的高度客製化彈性！</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2009-11-28%2Fpostid-208&from=http%3A%2F%2Fblog.frost.tw%2Fsite-built%2Fposton-2011-06-14%2Fpostid-1212">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">SEO 與 PHP Blog</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fweb-project%2Fposton-2010-03-03%2Fpostid-431&from=http%3A%2F%2Fblog.frost.tw%2Fsite-built%2Fposton-2011-06-14%2Fpostid-1212">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">DIY一個PHP留言板之規劃</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fweb-project%2Fposton-2010-03-08%2Fpostid-441&from=http%3A%2F%2Fblog.frost.tw%2Fsite-built%2Fposton-2011-06-14%2Fpostid-1212">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">DIY一個PHP留言板之資料存取(四)</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fweb-project%2Fposton-2010-03-04%2Fpostid-433&from=http%3A%2F%2Fblog.frost.tw%2Fsite-built%2Fposton-2011-06-14%2Fpostid-1212">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">DIY一個PHP留言板之資料存取(一)</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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>]]></content:encoded>
			<wfw:commentRss>http://blog.frost.tw/site-built/poston-2011-06-14/postid-1212/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>《弦也式插件開發術》序．Plugin 概論</title>
		<link>http://blog.frost.tw/code/poston-2011-02-22/postid-1120</link>
		<comments>http://blog.frost.tw/code/poston-2011-02-22/postid-1120#comments</comments>
		<pubDate>Tue, 22 Feb 2011 11:16:42 +0000</pubDate>
		<dc:creator>蒼時弦や</dc:creator>
				<category><![CDATA[程式語言]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[插件]]></category>
		<category><![CDATA[程式]]></category>
		<category><![CDATA[筆記]]></category>

		<guid isPermaLink="false">http://blog.frost.tw/?p=1120</guid>
		<description><![CDATA[因為我很懶惰，所以就把昨晚在討論版上發表的文章轉貼過來啦～ 這篇文章我想應該還有錯誤的地方。 （大概是我理解錯誤） 不過Discuz/WordPress的插件運行，大致上就是這種構造。 （註：注意事項那段真的是「有人很過份，把別人文章、錄好影片都轉貼」所以我才特地加上的……） 注意事項： 本文章為原創文章，假使未經原作者同意而任意轉載於本站以外的站點，原作者有權以法律途徑要求賠償。 假使欲轉載本文至本站以外之站點，需附上原文網址以及作者網站。 《弦也式插件開發術》序．Plugin 概論 @Author: 蒼時弦や @Website: http://frost.tw/ 一、Plugin 簡介 何謂 Plugin (插件) 呢？ 就字面上的意思，即是「插入」，即使這樣說明也難以理解是什麼意思。 以生活上的方式解釋，就像是樂高一般，將不同大小、形狀的方塊插入，組合出一個形體。 以線上遊戲來看，也許就是像「裝備」一樣，依照你的需求裝備上不同的道具。 簡而言之，插件提供了架站者個人化的選擇，也強化了架站機的功能。 二、何為 Module (模組) 在早期 Xoops, phpBB 時代，會有所謂Module或者Mod這類名詞。 他們與插件的差異，應該就是所謂的 Hook [註] 的使用。 模組就像是一台機器的零件一般，在你需要的時候放進去，組合成一台機器，或者改裝這個機器。 但插件則不同了，他像是晶片或者軟體一般，只需要安裝上去，就會自動調整你的機器。 以現在Server(主機)的CPU能力來看，即使使用Plugin的方式擴充，也不會碰上運算效率低下的問題。 （筆者推測早期模組的使用在於減少CPU使用，以及Hook技術的處理尚未成熟） 註：Hook &#8230; <a href="http://blog.frost.tw/code/poston-2011-02-22/postid-1120">Continue reading <span class="meta-nav">&#8594;</span></a><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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-21%2Fpostid-959&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-02-22%2Fpostid-1120">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">[筆記] PHP 的單例設計模式</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2009-10-19%2Fpostid-98&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-02-22%2Fpostid-1120">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Facebook Connect Plugin 使用心得</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2010-08-22%2Fpostid-663&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-02-22%2Fpostid-1120">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">PHP 中的 Array Sort (陣列排序)</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2010-08-15%2Fpostid-641&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-02-22%2Fpostid-1120">
                        <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.htm" 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>因為我很懶惰，所以就把昨晚在討論版上發表的文章轉貼過來啦～<br />
這篇文章我想應該還有錯誤的地方。<br />
（大概是我理解錯誤）</p>
<p>不過Discuz/WordPress的插件運行，大致上就是這種構造。<br />
（註：注意事項那段真的是「有人很過份，把別人文章、錄好影片都轉貼」所以我才特地加上的……）<br />
<span id="more-1120"></span></p>
<p><strong>注意事項：</strong><br />
本文章為原創文章，假使未經原作者同意而任意轉載於本站以外的站點，原作者有權以法律途徑要求賠償。<br />
<span style="color: #ff0000;"><strong>假使欲轉載本文至本站以外之站點，需附上原文網址以及作者網站。</strong></span></p>
<p><strong>《弦也式插件開發術》序．Plugin 概論</strong></p>
<p>@Author: 蒼時弦や<br />
@Website: <a href="http://frost.tw/" target="_blank">http://frost.tw/</a></p>
<p><strong>一、Plugin 簡介</strong><br />
何謂 Plugin (插件) 呢？<br />
就字面上的意思，即是「插入」，即使這樣說明也難以理解是什麼意思。<br />
以生活上的方式解釋，就像是樂高一般，將不同大小、形狀的方塊插入，組合出一個形體。<br />
以線上遊戲來看，也許就是像「裝備」一樣，依照你的需求裝備上不同的道具。</p>
<p>簡而言之，插件提供了架站者個人化的選擇，也強化了架站機的功能。</p>
<p><strong>二、何為 Module (模組)</strong><br />
在早期 Xoops, phpBB 時代，會有所謂Module或者Mod這類名詞。<br />
他們與插件的差異，應該就是所謂的 Hook [註] 的使用。<br />
模組就像是一台機器的零件一般，在你需要的時候放進去，組合成一台機器，或者改裝這個機器。<br />
但插件則不同了，他像是晶片或者軟體一般，只需要安裝上去，就會自動調整你的機器。</p>
<p>以現在Server(主機)的CPU能力來看，即使使用Plugin的方式擴充，也不會碰上運算效率低下的問題。<br />
（筆者推測早期模組的使用在於減少CPU使用，以及Hook技術的處理尚未成熟）</p>
<p>註：Hook &#8211; 鉤子，是與Plugin密切關係的一項處理，他可以協助Plugin在特定的位置增加或修改動作、訊息。</p>
<p><strong>三、Hook的概念</strong><br />
筆者之後將要介紹的WordPress, Discuz等架站機，都是使用 Hook 作為擴充的架站機。<br />
那麼，就必須瞭解 Hook 在 Plugin 上的意義了！</p>
<p>鉤子像是什麼東西呢？<br />
簡單的形容他，大概就像是一個標記，讓程式可以識別。<br />
不過，這樣也許還是非常抽象，但是筆者也想不到什麼好方法可以解釋Hook的意義。</p>
<p>而 Hook 是如何與 Plugin 作為關聯呢？<br />
這是一個非常簡單的概念，就如同前文所述的「標記」這個動作。<br />
不論是WordPress還是Discuz他們皆有共通的特色。<br />
那就是在特定的「點」有一段程式碼會運行某個 Hook 並且去喚醒 Plugin 內的程式碼。</p>
<p>也許 Hook 可以當作是鬧鐘，在某個時間把你叫醒一般。<br />
以 WordPress 的 Hook 為例子來看。<br />
在WordPress程式大多運行完畢後，會呼叫 init 這個鉤子（每個鉤子都有自己的名稱，這個是名為「初始化」的鉤子）<br />
此時，只要你的Plugin設定某段程式碼是 init 這個鉤子所呼叫的片段，那麼在 init 運行時，就會連同你的鉤子一同執行。</p>
<p><strong>四、WordPress的Hook (主動式)</strong><br />
就筆者認為，在WordPress去追加一個動作的方式來看，在WordPress上比較為「主動」<br />
何為主動呢？<br />
也就是需要開發者自行追加，才會有效果。</p>
<p>這邊我們以一小段程式碼為例子：</p>
<pre class="brush: php">&lt;?php
function my_hook()
{
//Here will do something...
}
add_action('init', 'my_hook');
?&gt;</pre>
<p>上述的程式碼將會在 init 這個 hook 點運行時，一併運行 my_hook 這個函式。<br />
這也就是 WordPress 的Hook運行方式。<br />
（沒有使用 add_action 或 add_filter 去告訴系統，有片段要再某個Hook運行，系統就不會去運行。）</p>
<p><strong>五、Discuz的Hook (被動式)</strong><br />
為什麼筆者稱Discuz的Hook為被動式呢？<br />
因為當開發者寫好他的程式碼片段後，只要 Hook 點運行，就會被呼叫。<br />
完全不需要自己主動去告訴Hook要運行的動作。</p>
<p>[註] 因為筆者長期沒有開發 Discuz 插件，因此以官方文件的代碼來解釋。</p>
<pre class="brush: php">//全局脚本嵌入点类
class plugin_identifier_CURSCRIPT[_DO] extends plugin_identifier {

function HookId_1() {
......
return ...;
}

function HookId_2() {
......
return ...;
}

......

}</pre>
<p>以上方程式碼的片段來看，插件都一律以 plugin_插件識別名 來做命名（物件）<br />
而對某個 Hook 新增動作時，就會以 plugin_插件識別名_動作文件 來做命名（物件）<br />
而 HookId 就是每個 Hook 的識別名稱了！<br />
如 viewthread 為閱讀文章相關的 Hook 動作。</p>
<p><strong>六、開發WordPress &amp; Discuz 插件的要點</strong><br />
使用 Hook 將會是這兩類架站機的重要觀念。<br />
並且要分別習慣兩種架站機其產生訊息的方式以及差異。<br />
如 WordPress 並無版模系統，並且有 Action Hook 以及 Filter Hook 兩種。<br />
Action Hook 單純做運算處理，屬於 Controller/Model 層面（控制/模型層）<br />
Filter Hook 則是負責輸出處理，屬於 Views 層面（視圖層）</p>
<p>而在Discuz上，一般訊息的顯示都以呼叫函式產生。<br />
大部分的返回訊息也是以 return 就能夠輸出。<br />
（某種意義上，在Discuz大部分的Hook都是Filter Hook）<br />
當想輸出頁面時，也需要使用特定函式才可輸出（還需建立版模）</p>
<p>不過，共通的要點就是熟悉這些 Hook 的位置以及使用時機。<br />
（在WordPress上有優先權的設置，而Discuz則無。）</p>
<p><strong>七、小結</strong><br />
雖然網路上的Plugin變化非常多，也有許多五花八門的運用。<br />
但探究其原理，實際上只有非常少的內容。<br />
整個 Plugin 技術，都是圍繞在 Hook 這個部份上。<br />
其餘的都是單純的 PHP 開發，只不過規模比較小而已。</p>
<p>當熟悉 Hook 之後，往後的 Plugin 開發就算是通行無阻了！</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-21%2Fpostid-959&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-02-22%2Fpostid-1120">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">[筆記] PHP 的單例設計模式</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2009-10-19%2Fpostid-98&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-02-22%2Fpostid-1120">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Facebook Connect Plugin 使用心得</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2010-08-22%2Fpostid-663&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-02-22%2Fpostid-1120">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">PHP 中的 Array Sort (陣列排序)</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2010-08-15%2Fpostid-641&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-02-22%2Fpostid-1120">
                        <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.htm" 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>]]></content:encoded>
			<wfw:commentRss>http://blog.frost.tw/code/poston-2011-02-22/postid-1120/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>[筆記] PHP 的單例設計模式</title>
		<link>http://blog.frost.tw/code/poston-2011-01-21/postid-959</link>
		<comments>http://blog.frost.tw/code/poston-2011-01-21/postid-959#comments</comments>
		<pubDate>Fri, 21 Jan 2011 13:30:56 +0000</pubDate>
		<dc:creator>蒼時弦や</dc:creator>
				<category><![CDATA[程式語言]]></category>
		<category><![CDATA[Codeigniter]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[學習]]></category>
		<category><![CDATA[生活]]></category>
		<category><![CDATA[程式]]></category>
		<category><![CDATA[筆記]]></category>

		<guid isPermaLink="false">http://blog.frost.tw/?p=959</guid>
		<description><![CDATA[前天在討論版上問了個問題，雖然得到了解答。 自己測試也得到了一個滿意的結果，不過我還是不解「不會重複消耗記憶體嗎？」的這個疑惑。 從我使用 Codeigniter 這個 Framework 一段時間後，我開始有了這個疑問。 而在得到新名詞「單例模式」時，我才頓悟。 （得到這名詞的方式有點小白，人家大大有點不耐煩了……不過我是真的第一次知道……） 弦也認為繁體中文章，阿育大大在色胚子部落格上的翻譯最為清楚好懂。 單例設計模式的用途 假使弦也沒有不幸的理解錯誤，那麼大概就是「避免重複產生實例」 依照弦也所蒐集到的資料，也就是如「資料庫物件」在每次使用時都會使用 new 產生一次，但非常消耗資源。 那麼最好的方法就是「限制產生」而且確保「只產生一次」來避免這個問題。 （弦也一直不解的其實就是Framework使用這麼多物件，記憶體是否會多次消耗。以此看來，這種方式就是對其做了處理。） 如何實做單例模式 就網路上的範例來看，大致至上都是如下的作法。 &#60;?php /** * @package 單例設計模式 * @author 蒼時弦也 */ class Core { private static $instance; //設置為靜態成員、私有 private function __construct() //將建構式設置為私有，避免外部調用 { &#8230; <a href="http://blog.frost.tw/code/poston-2011-01-21/postid-959">Continue reading <span class="meta-nav">&#8594;</span></a><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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-17%2Fpostid-949&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-21%2Fpostid-959">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Aotoki’s Codeigniter Day 1 – 安裝與產生第一個頁面</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2011-01-20%2Fpostid-955&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-21%2Fpostid-959">
                        <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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-16%2Fpostid-948&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-21%2Fpostid-959">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">PHP Framework 的一天</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2010-08-22%2Fpostid-663&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-21%2Fpostid-959">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">PHP 中的 Array Sort (陣列排序)</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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>前天在討論版上問了個問題，雖然得到了解答。<br />
自己測試也得到了一個滿意的結果，不過我還是不解「不會重複消耗記憶體嗎？」的這個疑惑。</p>
<p>從我使用 Codeigniter 這個 Framework 一段時間後，我開始有了這個疑問。<br />
而在得到新名詞「單例模式」時，我才頓悟。<br />
（得到這名詞的方式有點小白，人家大大有點不耐煩了……不過我是真的第一次知道……）<br />
<span id="more-959"></span><br />
弦也認為繁體中文章，<a href="http://blog.colorbase.tw/about" target="_blank">阿育</a>大大在<a href="http://blog.colorbase.tw/programming/625" target="_blank">色胚子</a>部落格上的翻譯最為清楚好懂。</p>
<p><strong>單例設計模式的用途</strong></p>
<p>假使弦也沒有不幸的理解錯誤，那麼大概就是「避免重複產生實例」<br />
依照弦也所蒐集到的資料，也就是如「資料庫物件」在每次使用時都會使用 new 產生一次，但非常消耗資源。<br />
那麼最好的方法就是「限制產生」而且確保「只產生一次」來避免這個問題。<br />
（弦也一直不解的其實就是Framework使用這麼多物件，記憶體是否會多次消耗。以此看來，這種方式就是對其做了處理。）</p>
<p><strong>如何實做單例模式</strong></p>
<p>就網路上的範例來看，大致至上都是如下的作法。</p>
<pre class="brush: php">&lt;?php
/**
 * @package 單例設計模式
 * @author 蒼時弦也
 */

class Core
{

  private static $instance; //設置為靜態成員、私有 

  private function __construct() //將建構式設置為私有，避免外部調用
  {
    //建構這個物件 Ex. 建立資料庫連接
  }

  public static function getInstance() //取得實例，物件會在這邊被建立
  {
    if(!self::$instance) //檢查時例是否存在（檢查方法蠻多種的，也有用 != NULL 檢查）
    {
      self::$instance = new Core(); //不存在時產生實例
    }
    return self::$instance; //傳回實例
  }

  //其他的處理在這
}

?&gt;
</pre>
<p>重點依照弦也理解，有下面幾項。</p>
<ul>
<li>建構子私有（避免外部調用，所以不會發生被產生第二次的情況）</li>
<li>有getInstance()之類的靜態方法（永遠用這個方法取得實例，因此實例被產生時永遠不會被產生第二次）</li>
<li>將 new Core() 改為 Core::getInstance() 調用（畢竟建構子私有無法再用 new 產生）</li>
</ul>
<p><strong>實做實驗</strong></p>
<p>弦也在學程式上真的就是「不打不相識」<br />
所以直接用 memory_get_usage() 這個函式來取得記憶體用量。<br />
並且比較兩個方法的記憶體消耗。</p>
<p>結果如下：</p>
<blockquote><p>Start Memory<br />
Memory used: 208</p>
<p>I&#8217;m traditional method!<br />
Memory used: 552</p>
<p>I&#8217;m traditional method!<br />
Memory used: 748</p>
<p>I&#8217;m traditional method!<br />
Memory used: 812</p>
<p>Free Memory<br />
Memory used: 812</p>
<p>Single Instance Method Start!</p>
<p>I&#8217;m single instance method!<br />
Memory used: 1128</p>
<p>Memory used: 1128</p>
<p>Memory used: 1128</p></blockquote>
<p>空行可不是失敗，而是弦也把輸出放在建構子裡面。</p>
<p>原始碼：</p>
<pre class="brush: php">&lt;?php
/**
 * @package 實例測試
 * @author 蒼時弦也
 */

class Traditional
{
 function __construct()
 {
 echo "I'm traditional method!";
 }

}

class SingleInstance
{
 private static $instance;

 private function __construct()
 {
 echo "I'm single instance method!";
 }

 public static function getInstance()
 {
 if(!self::$instance)
 {
 self::$instance = new SingleInstance();
 }
 return self::$instance;
 }

}

$start_used = memory_get_usage();

//Step 0 # Statr
echo 'Start Memory';
echo '&lt;br /&gt;Memory used: '.(memory_get_usage() - $start_used).'&lt;br /&gt;&lt;br /&gt;';
//Step 1 # Traditional Run 1
$obj = new Traditional();
echo '&lt;br /&gt;Memory used: '.(memory_get_usage() - $start_used).'&lt;br /&gt;&lt;br /&gt;';
//Step 2 # Traditional Run 2 (Replace)
$obj = new Traditional();
echo '&lt;br /&gt;Memory used: '.(memory_get_usage() - $start_used).'&lt;br /&gt;&lt;br /&gt;';
//Step 3 # Traditional Run 3 (New Varible)
$obj2 = new Traditional();
echo '&lt;br /&gt;Memory used: '.(memory_get_usage() - $start_used).'&lt;br /&gt;&lt;br /&gt;';
//Step 4 # Free Memory
echo 'Free Memory';
echo '&lt;br /&gt;Memory used: '.(memory_get_usage() - $start_used).'&lt;br /&gt;&lt;br /&gt;';

//Start Single Instance Method
echo 'Single Instance Method Start!&lt;br /&gt;&lt;br /&gt;';

//Step 5 # Single Instance Run 1
$obj = SingleInstance::getInstance();
echo '&lt;br /&gt;Memory used: '.(memory_get_usage() - $start_used).'&lt;br /&gt;&lt;br /&gt;';
//Step 6 # Single Instance Run 2 (Replace)
$obj = SingleInstance::getInstance();
echo '&lt;br /&gt;Memory used: '.(memory_get_usage() - $start_used).'&lt;br /&gt;&lt;br /&gt;';
//Step 7 # Single Instance Run 3 (New Varible)
$obj2 = SingleInstance::getInstance();
echo '&lt;br /&gt;Memory used: '.(memory_get_usage() - $start_used).'&lt;br /&gt;&lt;br /&gt;';

?&gt;</pre>
<p>從原始碼可以看到，每次運行都輸出一次記憶體使用。<br />
直到開始使用單例模式後，記憶體就維持不變。</p>
<p>這在減少記憶體使用上，可以說一個大改進吧！<br />
（多虧了這個機會，弦也可是學到了很棒的知識呢！）</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-17%2Fpostid-949&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-21%2Fpostid-959">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Aotoki’s Codeigniter Day 1 – 安裝與產生第一個頁面</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2011-01-20%2Fpostid-955&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-21%2Fpostid-959">
                        <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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-16%2Fpostid-948&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-21%2Fpostid-959">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">PHP Framework 的一天</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2010-08-22%2Fpostid-663&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-21%2Fpostid-959">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">PHP 中的 Array Sort (陣列排序)</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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>]]></content:encoded>
			<wfw:commentRss>http://blog.frost.tw/code/poston-2011-01-21/postid-959/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>所謂的學習悲劇大概就是如此……</title>
		<link>http://blog.frost.tw/life/poston-2011-01-20/postid-955</link>
		<comments>http://blog.frost.tw/life/poston-2011-01-20/postid-955#comments</comments>
		<pubDate>Thu, 20 Jan 2011 11:13:59 +0000</pubDate>
		<dc:creator>蒼時弦や</dc:creator>
				<category><![CDATA[生活雜記]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[學習]]></category>
		<category><![CDATA[想法]]></category>
		<category><![CDATA[校園]]></category>
		<category><![CDATA[生活]]></category>
		<category><![CDATA[程式]]></category>
		<category><![CDATA[經驗]]></category>
		<category><![CDATA[雜記]]></category>

		<guid isPermaLink="false">http://blog.frost.tw/?p=955</guid>
		<description><![CDATA[其實在學習東西的問題上，我應該是探討很多次了！ 不過，每次碰到類似的情況，難免就是想抱願一番。 說實在的。 「現在太多人『動口不動手』即使動手也『不動腦』」 整個悲劇，一個很嚴重的學習悲劇！ 雖然我是不知道為什麼會讓大家發展成這樣。 也許是Yahoo的糟糕知識+或者是網友的力量造成的。 不過，在一項領域內作為專精者和不專精者的區分就很輕鬆了！ 有人幾個月就通，有人跟便秘一樣一直想不出來。 差異也不過就是那個動作、那個決心而已吧！ 再加上，孔子也說「思而不學則怠，學而不思則罔。」 此時，我真的對於那種「學而不思的人感到憂心。」 思而不學，我想大概說夢話很久了…… 而也因為沒在實做，所以久了也看不到他們有啥進展。 （不過好處是可以把他放一邊，等他說完他的理想後打發掉……） 不過，學而不思就麻煩了！ 稍微好些的人，就會去學習。 對，和之前討論不學習的人比起來，他們好多了！ 但是，他們很多其實都會，但是就是「迷惘」 說起來，這也是正常情況。 不過，到底為什麼會產生「悲劇」呢？ 我猜，大概就是「不知變通」 簡單來說，他們學到新東西後，就會覺得「不要亂動」 我覺得，台灣的教育制度讓大家得了兩種病。 「前面只有一條路的有勇無謀。」 「把頭伸出去就會受傷的縮頭烏龜。」 其實路很多，需要靠自己去開拓。 但是很多人都選擇升學，無盡升學。 其實很多成功者他們並沒有完全的把重心放在課業上。 不過，大家常會聽到「把書讀好就會成功。」 那是多麼虛偽的言語阿！ 「把書讀好會成功的，只有喜歡讀書的人。」 「不喜歡讀書的人不一定會失敗，但他得先找到自己的路。」 為什麼到了高三，還有一堆人不知道該讀什麼？ 「機會是給準備好的人！」 因為他們可能不喜歡讀書，又被迫讀書。 說實在的，要我讀書我也覺得很煩。 但是讀起「資訊、設計」這類書籍，我又是恨不得多看些。 「喜歡，還有不喜歡的差異。」 就好像你逼一隻雞飛起來，不是醫生的料就做不成優秀的醫生。 &#8230; <a href="http://blog.frost.tw/life/poston-2011-01-20/postid-955">Continue reading <span class="meta-nav">&#8594;</span></a><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.htm?url=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2010-11-30%2Fpostid-860&from=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2011-01-20%2Fpostid-955">
                        <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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-21%2Fpostid-959&from=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2011-01-20%2Fpostid-955">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">[筆記] PHP 的單例設計模式</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2011-02-21%2Fpostid-1118&from=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2011-01-20%2Fpostid-955">
                        <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.htm?url=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2011-09-10%2Fpostid-1251&from=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2011-01-20%2Fpostid-955">
                        <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.htm" 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>其實在學習東西的問題上，我應該是探討很多次了！<br />
不過，每次碰到類似的情況，難免就是想抱願一番。</p>
<p>說實在的。<br />
「現在太多人『動口不動手』即使動手也『不動腦』」<br />
整個悲劇，一個很嚴重的學習悲劇！<br />
<span id="more-955"></span><br />
雖然我是不知道為什麼會讓大家發展成這樣。<br />
也許是Yahoo的糟糕知識+或者是網友的力量造成的。</p>
<p>不過，在一項領域內作為專精者和不專精者的區分就很輕鬆了！<br />
有人幾個月就通，有人跟便秘一樣一直想不出來。<br />
差異也不過就是那個動作、那個決心而已吧！</p>
<p>再加上，孔子也說「思而不學則怠，學而不思則罔。」<br />
此時，我真的對於那種「學而不思的人感到憂心。」<br />
思而不學，我想大概說夢話很久了……</p>
<p>而也因為沒在實做，所以久了也看不到他們有啥進展。<br />
（不過好處是可以把他放一邊，等他說完他的理想後打發掉……）</p>
<p>不過，學而不思就麻煩了！<br />
稍微好些的人，就會去學習。<br />
對，和之前討論不學習的人比起來，他們好多了！</p>
<p>但是，他們很多其實都會，但是就是「迷惘」<br />
說起來，這也是正常情況。<br />
不過，到底為什麼會產生「悲劇」呢？</p>
<p>我猜，大概就是「不知變通」<br />
簡單來說，他們學到新東西後，就會覺得「不要亂動」<br />
我覺得，台灣的教育制度讓大家得了兩種病。<br />
「前面只有一條路的有勇無謀。」<br />
「把頭伸出去就會受傷的縮頭烏龜。」</p>
<p>其實路很多，需要靠自己去開拓。<br />
但是很多人都選擇升學，無盡升學。<br />
其實很多成功者他們並沒有完全的把重心放在課業上。<br />
不過，大家常會聽到「把書讀好就會成功。」</p>
<p>那是多麼虛偽的言語阿！<br />
「把書讀好會成功的，只有喜歡讀書的人。」<br />
「不喜歡讀書的人不一定會失敗，但他得先找到自己的路。」</p>
<p>為什麼到了高三，還有一堆人不知道該讀什麼？<br />
「機會是給準備好的人！」</p>
<p>因為他們可能不喜歡讀書，又被迫讀書。<br />
說實在的，要我讀書我也覺得很煩。<br />
但是讀起「資訊、設計」這類書籍，我又是恨不得多看些。<br />
「喜歡，還有不喜歡的差異。」</p>
<p>就好像你逼一隻雞飛起來，不是醫生的料就做不成優秀的醫生。<br />
所以我覺得那鯉魚想躍龍門，真的很悲哀……</p>
<p>台灣有俗諺「行行出狀元。」<br />
真的，每種職業都會有其優秀者存在。<br />
但是這些似乎只試用以前那種「打拼」的時代。<br />
在這個「現代」人們都盲目的從學流。</p>
<p>最後，也不過就是渾渾噩噩的度日而已吧！</p>
<p>一大堆工程師改行什麼的，大家也不是沒聽過。<br />
「為什麼改行？」<br />
「因為，工程師是被逼去當的！」</p>
<p>在這個論點上，我就覺得美國人做的不錯。<br />
今天看新聞，一個八歲小孩因為喜歡 RAP 而努力。<br />
在網路上也算是蠻紅的，面對批評的態度也是很正面、正確。</p>
<p>但是，如果一個台灣的八歲小還很喜歡 RAP 而且天賦普普時。<br />
台灣的父母會怎麼做？<br />
「抓來罵一頓，叫他好好讀書！」<br />
假使這孩子在網路上面對了批評呢？<br />
「很快就覺得失落，抑或是反擊回去吧！」<br />
為什麼會覺得失落？<br />
因為在他努力的過程中，太多家人都這樣壓抑他了！<br />
（連網友都不支持他，那個動力很快就被壓下去了！）<br />
為什麼會反擊？<br />
台灣的媒體、連續劇，不就撥這些嗎？<br />
沒網路的有電視，沒電視的有網路。</p>
<p>如果父母沒有細心教導，這孩子能正向回應批評嗎？<br />
台灣大部分父母都是認為：「孩子書讀好，以後就會好！」</p>
<p>我覺得，這是對自己孩子的一種不信任。<br />
也許是對自己基因自卑的表現（我是這樣推測）</p>
<p>我的家庭情況也有點特殊，再加上我成長的方式也異常。<br />
即使如此，讓我老爸完全相信我的能力。<br />
也是花上個五六年。</p>
<p>這也很可能和中國的民族性，保守有關係吧！<br />
（即使是我也難逃保守思想的一劫……）</p>
<p>我們的學習資訊「封閉」在一個層面上。<br />
「讀好書，就能過好日子。」</p>
<p>我認為，這是該改觀的時候了！</p>
<p>我們應該試著去尋找自己的道路。<br />
「思考。」<br />
（某人硬拉回主題，雖然找自己的道路確實要思考……）</p>
<p>又一種說法，喜歡一個東西是什麼感覺？<br />
「沉溺於其中，盡情的『鑽研』」<br />
所以才會有「廢寢忘食」這句成語阿！</p>
<p>學習雖不能閉門造車，但也是需要鑽研的，對吧？<br />
網路供應新資訊，而自身的思考就是成長的關鍵。</p>
<p>說了一堆廢話，還未提到寫這篇文章的原因。<br />
昨晚，一位新網友進入我的MSN列表。<br />
是因為他有 PHP 問題，所以才找我的。</p>
<p>我幫他檢查了一下之後，發現問題真的挺多的！<br />
但，最主要的問題並非他會不會。<br />
而是他的思考，太少。<br />
程式這種東西在學習過程上需要思考更多（除了學習外，還要習慣。）</p>
<p>他遇到錯誤，就只是不斷地查資料、發問。<br />
的確，這是個很棒的、很優秀的方法。</p>
<p>但，他忘記思考為什麼會有問題。<br />
「學思並重。」<br />
他做到學，但學不夠。<br />
但，他思考不夠多。</p>
<p>在我 Google 資料時，我通常會著重幾個點。<br />
新東西，這是一開始學的。<br />
問題，這是我學會後碰上的問題。<br />
原來的東西，如果問題不解，可能我對新東析還是不熟。</p>
<p>就如同昨天測試 PHP Function 遞值的問題一般。<br />
我學了 call_user_func_array 這個函式的運用。<br />
我做了思考，但是運用上無解。<br />
於是我回去找尋我學習時的盲點。<br />
發現，我的遞值是缺了步驟。</p>
<p>於是，問題解決了！</p>
<p>對我來說，學習悲劇，就是「即使學了，也不能去好好思考。」</p>
<p>也許是這樣我才討厭回答別人問題吧！<br />
「因為太多太多的人，得到答案後，沒有繼續思考。」<br />
這也是我認為「經驗」很重要的原因。</p>
<p>最近我幫老師寫程式，老師一直說我除錯的速度很快。<br />
實際上不是，那是一種習慣。<br />
「因為每次都錯，所以就會習慣的檢查。」<br />
「因為錯誤很明顯是他，所以會特別去關注！」</p>
<p>在學科上的學習也是一樣。<br />
「老是出錯的問題，不去關注，那麼永遠都會錯。」<br />
「問題的點在哪，就要特別的去探討。」<br />
我想，這是我即使不怎麼在課業上用心，也不至於被當的原因吧！</p>
<p>學習的方法。<br />
「還有很多人，沒有仔細去思考自己的方法。」<br />
「思考，真的很重要。畢竟，學習大家常常做。」</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2010-11-30%2Fpostid-860&from=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2011-01-20%2Fpostid-955">
                        <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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-21%2Fpostid-959&from=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2011-01-20%2Fpostid-955">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">[筆記] PHP 的單例設計模式</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2011-02-21%2Fpostid-1118&from=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2011-01-20%2Fpostid-955">
                        <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.htm?url=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2011-09-10%2Fpostid-1251&from=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2011-01-20%2Fpostid-955">
                        <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.htm" 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>]]></content:encoded>
			<wfw:commentRss>http://blog.frost.tw/life/poston-2011-01-20/postid-955/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP 中的 Function (函式) 數值傳遞測試（無解）</title>
		<link>http://blog.frost.tw/code/poston-2011-01-19/postid-953</link>
		<comments>http://blog.frost.tw/code/poston-2011-01-19/postid-953#comments</comments>
		<pubDate>Wed, 19 Jan 2011 11:29:34 +0000</pubDate>
		<dc:creator>蒼時弦や</dc:creator>
				<category><![CDATA[程式語言]]></category>
		<category><![CDATA[bbPress]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[生活]]></category>
		<category><![CDATA[程式]]></category>

		<guid isPermaLink="false">http://blog.frost.tw/?p=953</guid>
		<description><![CDATA[在 bbPress/WordPress 中，使用 Hook 製作插件時。 Filter 功能，如果直接使用 echo 輸出內容，那麼優先度在其之後者都無法顯示。 但是，如果將訊息處理後 return 回去，後面的函式又可以繼續處理。 但，似乎沒有使用 &#38; 去參照，到底是什麼情況呢？ 弦也決定親身測試，這個神覓得東西！ 測試 1 &#8211; 單純輸出 function do_func( $str ){ call_user_func_array('op2', array($str)); call_user_func_array('op3', array($str)); } function op1( $str ){ //Return to op2 return do_func($str); } function &#8230; <a href="http://blog.frost.tw/code/poston-2011-01-19/postid-953">Continue reading <span class="meta-nav">&#8594;</span></a><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.htm?url=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2011-01-14%2Fpostid-944&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-19%2Fpostid-953">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">12月 ~ 1月程式隨手札記</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-04%2Fpostid-925&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-19%2Fpostid-953">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">小試身手做 bbPress 簡易虛擬貨幣系統</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fsite-built%2Fposton-2010-12-12%2Fpostid-884&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-19%2Fpostid-953">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">bbPress 的 RPG System 製作</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fweb-project%2Fposton-2010-03-03%2Fpostid-431&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-19%2Fpostid-953">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">DIY一個PHP留言板之規劃</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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>在 bbPress/WordPress 中，使用 Hook 製作插件時。<br />
Filter 功能，如果直接使用 echo 輸出內容，那麼優先度在其之後者都無法顯示。</p>
<p>但是，如果將訊息處理後 return 回去，後面的函式又可以繼續處理。<br />
但，似乎沒有使用 &amp; 去參照，到底是什麼情況呢？</p>
<p>弦也決定親身測試，這個神覓得東西！<br />
<span id="more-953"></span><br />
測試 1 &#8211; 單純輸出</p>
<pre class="brush:php">
function do_func( $str ){
	call_user_func_array('op2', array($str));
	call_user_func_array('op3', array($str));
}

function op1( $str ){
	//Return to op2
	return do_func($str);
}

function op2( $str ){
	echo $str.'2';
}

function op3( $str ){
	echo $str.'3';
}

echo op1('hello');
</pre>
<p>結果：hello2hello3</p>
<p>測試2 &#8211; op2改為return</p>
<pre class="brush:php">
function op2( $str ){
	return $str.'2';
}
</pre>
<p>結果：hello3<br />
看起來，此時的 hello2 已經被 hello3 蓋過去了！<br />
再來測試 op3 也改為 return 時，是否會傳遞參數。</p>
<pre class="brush: php">
function op3( $str ){
	return $str.'3';
}
</pre>
<p>結果：空<br />
看起來，似乎是不會做任何傳遞動作的！</p>
<p>加上參照看看！</p>
<pre class="brush: php">
function do_func( &#038;$str ){
	call_user_func_array('op2', array($str));
	call_user_func_array('op3', array($str));
}
</pre>
<p>結果：空<br />
看起來也不行，也許哪裡漏了些東西！</p>
<p>打開 function.plugin-api.php 看看。</p>
<pre class="brush:php">
function apply_filters($tag, $value) {
	global $wp_filter, $merged_filters, $wp_current_filter;

	$args = array();
	$wp_current_filter[] = $tag;

	// Do 'all' actions first
	if ( isset($wp_filter['all']) ) {
		$args = func_get_args();
		_wp_call_all_hook($args);
	}

	if ( !isset($wp_filter[$tag]) ) {
		array_pop($wp_current_filter);
		return $value;
	}

	// Sort
	if ( !isset( $merged_filters[ $tag ] ) ) {
		ksort($wp_filter[$tag]);
		$merged_filters[ $tag ] = true;
	}

	reset( $wp_filter[ $tag ] );

	if ( empty($args) )
		$args = func_get_args();

	do {
		foreach( (array) current($wp_filter[$tag]) as $the_ )
			if ( !is_null($the_['function']) ){
				$args[1] = $value;
				$value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
			}

	} while ( next($wp_filter[$tag]) !== false );

	array_pop( $wp_current_filter );

	return $value;
}
</pre>
<p>看起來我們的 call_user_func_array() 也沒有問題，在 -Press 中也沒有使用 &#038; 做參照。<br />
對 op1 做調整看看。</p>
<pre class="brush:php">
function op1( $str ){
	//Return to op2
	echo $str;
	do_func($str);
}
</pre>
<p>結果：hello<br />
問題也不在 op1 身上，這倒是讓整個過程成了一個謎阿！</p>
<p>既然現在無解，就只好暫時放在一邊。<br />
也許哪天做測試時，會測出 -Press 為什麼可以傳遞數值的原因！<br />
（弦也自己寫的 Hook 也做不到，真是神奇！）</p>
<p>&#8212;<br />
17:49 補充</p>
<p>原來，一個一直有一個盲點。<br />
「程式的『循序』原則！」</p>
<p>因為 -Press 都用 Loop 去做，所以我們沒發現他不斷地 Replace $value 這個變數。<br />
正解：</p>
<pre class="brush: php">
function do_func( $str ){
	for($i = 2; $i < 3; $i++){
	$str = call_user_func_array('op2', array($str));
	$str = call_user_func_array('op3', array($str));

	return $str;
}
</pre>
<p>這樣一來，就能不斷串接了！<br />
（也可以避開一些用echo直接輸出的問題呢！）</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Flife%2Fposton-2011-01-14%2Fpostid-944&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-19%2Fpostid-953">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">12月 ~ 1月程式隨手札記</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-04%2Fpostid-925&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-19%2Fpostid-953">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">小試身手做 bbPress 簡易虛擬貨幣系統</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fsite-built%2Fposton-2010-12-12%2Fpostid-884&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-19%2Fpostid-953">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">bbPress 的 RPG System 製作</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fweb-project%2Fposton-2010-03-03%2Fpostid-431&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-19%2Fpostid-953">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">DIY一個PHP留言板之規劃</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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>]]></content:encoded>
			<wfw:commentRss>http://blog.frost.tw/code/poston-2011-01-19/postid-953/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用 Session 儲存 Object</title>
		<link>http://blog.frost.tw/code/poston-2011-01-18/postid-951</link>
		<comments>http://blog.frost.tw/code/poston-2011-01-18/postid-951#comments</comments>
		<pubDate>Tue, 18 Jan 2011 11:29:23 +0000</pubDate>
		<dc:creator>蒼時弦や</dc:creator>
				<category><![CDATA[程式語言]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Session]]></category>
		<category><![CDATA[程式]]></category>
		<category><![CDATA[筆記]]></category>

		<guid isPermaLink="false">http://blog.frost.tw/?p=951</guid>
		<description><![CDATA[前幾天，我正在思考 PHP 快取的問題。 畢竟，每次都要運算，總會消耗一些程式運行的時間。 使用 Framework 或者大量的 Include 時，基本運作時間就會增加。 是否有辦法改善呢？ 此時我就把腦筋動到 SESSION 上面了！ 於是我就利用課餘時間 Google "PHP Store object in session" 的關鍵字。 找到了這篇介紹 Session 的文章： http://www.phpriot.com/articles/intro-php-sessions/8 看起來，我的腦筋動對地方了！ 既然可以儲存，那麼就來實做一下測試吧！ 簡易 User Object Store in Session 在這邊我們將一個用戶的資料都丟進 Session 裡面存取。 功能： 登入/登出 取得帳號、暱稱 下面弦也製造了兩個完全無意義的 &#8230; <a href="http://blog.frost.tw/code/poston-2011-01-18/postid-951">Continue reading <span class="meta-nav">&#8594;</span></a><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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-21%2Fpostid-959&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-18%2Fpostid-951">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">[筆記] PHP 的單例設計模式</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2010-08-12%2Fpostid-636&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-18%2Fpostid-951">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">PHP上一直忽略的小常識</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-02-22%2Fpostid-1120&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-18%2Fpostid-951">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">《弦也式插件開發術》序．Plugin 概論</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.htm?url=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2010-08-22%2Fpostid-663&from=http%3A%2F%2Fblog.frost.tw%2Fcode%2Fposton-2011-01-18%2Fpostid-951">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">PHP 中的 Array Sort (陣列排序)</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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 快取的問題。<br />
畢竟，每次都要運算，總會消耗一些程式運行的時間。<br />
使用 Framework 或者大量的 Include 時，基本運作時間就會增加。</p>
<p>是否有辦法改善呢？<br />
此時我就把腦筋動到 SESSION 上面了！<br />
<span id="more-951"></span><br />
於是我就利用課餘時間 Google "PHP Store object in session" 的關鍵字。<br />
找到了這篇介紹 Session 的文章：<br />
<a href="http://www.phpriot.com/articles/intro-php-sessions/8" target="_blank">http://www.phpriot.com/articles/intro-php-sessions/8</a></p>
<p>看起來，我的腦筋動對地方了！</p>
<p>既然可以儲存，那麼就來實做一下測試吧！<br />
簡易 User Object Store in Session</p>
<p>在這邊我們將一個用戶的資料都丟進 Session 裡面存取。<br />
功能：</p>
<ul>
<li>登入/登出</li>
<li>取得帳號、暱稱</li>
</ul>
<p>下面弦也製造了兩個完全無意義的 Class 來玩。<br />
（當作順便摸熟 OOP 的玩具了……）</p>
<p>user.php</p>
<pre class="brush: php">&lt;?php
//User Class

class User
{
 static private $username;
 static private $nickname;

 static public function login($username, $password)
 {
 if(self::checkUser($username) &amp;&amp; ($username == $password)){
 self::$username = $username;
 self::$nickname = '['.substr($username,0,4).']Nick'.intval(substr($username, 4));
 return true;
 }else{
 return false;    
 }
 }

 function checkUser($username){
 return ((intval(substr( $username, 4 ))^2)%2 == 0) &amp;&amp; $username != NULL;
 }
}

class CurrentUser extends User
{

 function __construct($username)
 {
 $this-&gt;username = $username;
 $this-&gt;nickname = '['.substr($username,0,4).']Nick'.intval(substr($username, 4));
 }

 function logout()
 {
 $this-&gt;username = NULL;    
 }

 function getNick()
 {
 return $this-&gt;nickname;    
 }

 function checkLogin()
 {
 return $this-&gt;checkUser($this-&gt;username);
 }

}</pre>
<p>index.php</p>
<pre class="brush: php">&lt;?php
//儲存物件於Session

include( 'user.php' );

session_start(); //Session Start

if($_POST['submit'] == 'Login'){
 if(User::login($_POST['username'], $_POST['password'])){
 session_register('user');
 $_SESSION['user'] = new CurrentUser($_POST['username']);
 header("Location:index.php");    
 }else{
 echo 'Login Failed!&lt;br /&gt;';    
 }
}

if(isset($_SESSION['user'])){
 $user = $_SESSION['user'];
 if($user-&gt;checkLogin())
 echo 'Current User is ', $user-&gt;getNick();
 else{
 $user-&gt;logout();
 session_unregister('user');
 header("Location:index.php");
 }

 //var_dump($_SESSION['user']-&gt;username);

}else{
 ?&gt;
 You aren't login!
 &lt;p&gt;
 &lt;form action="" method="post"&gt;
 Username: &lt;input name="username" type="text" /&gt;&lt;br /&gt;
 Password: &lt;input name="password" type="password" /&gt;&lt;br /&gt;
 &lt;input name="submit" type="submit" value="Login" /&gt;
 &lt;/form&gt;
 &lt;/p&gt;
 &lt;?php
}

?&gt;</pre>
<p>登入挺簡單的，只要輸入任意四個字+數字即可。<br />
這個數字需要為 (N^2)%2 == 0 的數字。</p>
<p>使用後就可以在有 Session 的情況下呼叫 CurrentUser 這個 Object 去做動作摟！</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.frost.tw/code/poston-2011-01-18/postid-951/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Aotoki&#8217;s Codeigniter Day 1 &#8211; 安裝與產生第一個頁面</title>
		<link>http://blog.frost.tw/code/poston-2011-01-17/postid-949</link>
		<comments>http://blog.frost.tw/code/poston-2011-01-17/postid-949#comments</comments>
		<pubDate>Mon, 17 Jan 2011 11:05:24 +0000</pubDate>
		<dc:creator>蒼時弦や</dc:creator>
				<category><![CDATA[程式語言]]></category>
		<category><![CDATA[Codeigniter]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[架站]]></category>
		<category><![CDATA[程式]]></category>

		<guid isPermaLink="false">http://blog.frost.tw/?p=949</guid>
		<description><![CDATA[經過一天的嘗試，弦也大致上決定採用 Codeigniter 作為自己的夥伴。 雖然之後會嘗試自己開發一個 Framework , 不過功用還是有差。 （畢竟每種 Framework 都有其特性，弦也自己的大概是對其他人很不實用的……） 廢話不多說，我們先來下載 Codeigniter 以及安裝這個 Framework 吧！ （與其說是安裝，不如說是配置。） 我們選用的是 Codeigniter 1.7.3 版，直接在 下載頁面 點選下載連結即可。 完成後，第一件事就是解壓縮。 值後將 user_gulide 以外的檔案上傳到網站，或者你的測試伺服器。 註：弦也的測試伺服器是嵌入在Windows的coLinux(Debian)因此複製到 C:\coLinux\www\ci (弦也做的Link處理，以及要運作的目錄 接著，大家先將 system 裡面的 application 複製到根目錄，現在的目錄狀況大致上會如下。 ci (Root) - application - system &#8230; <a href="http://blog.frost.tw/code/poston-2011-01-17/postid-949">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>經過一天的嘗試，弦也大致上決定採用 Codeigniter 作為自己的夥伴。<br />
雖然之後會嘗試自己開發一個 Framework , 不過功用還是有差。<br />
（畢竟每種 Framework 都有其特性，弦也自己的大概是對其他人很不實用的……）</p>
<p>廢話不多說，我們先來<a href="http://www.codeigniter.org.tw/downloads" target="_blank">下載 Codeigniter</a> 以及安裝這個 Framework 吧！<br />
（與其說是安裝，不如說是配置。）<br />
<span id="more-949"></span><br />
我們選用的是 Codeigniter 1.7.3 版，直接在 <a href="http://www.codeigniter.org.tw/downloads" target="_blank">下載頁面</a> 點選下載連結即可。</p>
<p>完成後，第一件事就是解壓縮。<br />
值後將 user_gulide 以外的檔案上傳到網站，或者你的測試伺服器。<br />
註：弦也的測試伺服器是嵌入在Windows的coLinux(Debian)因此複製到 C:\coLinux\www\ci (弦也做的Link處理，以及要運作的目錄</p>
<p>接著，大家先將 system 裡面的 application 複製到根目錄，現在的目錄狀況大致上會如下。<br />
ci (Root)<br />
- application<br />
- system<br />
- index.php</p>
<p>如果你有 Rewrite Module 可以啟用，弦也建議新增一個 .htaccess 檔到根目錄來做 Rewrite 處理。<br />
.htaccess 檔內容：<br />
<code><br />
RewriteEngine On<br />
RewriteCond $1 !^(index\.php|images|robots\.txt)<br />
RewriteRule ^(.*)$ index.php/$1 [L]<br />
</code><br />
上面簡單的讓 index.php 這個 Front 去 Handler 整個 Framework 來處理。<br />
（MVC架構都是由 Router 去處理，而 index.php 就是啟動Router 的媒介。）</p>
<p>接下來，就是簡單編輯 application/config/config.php 這個設定擋了！<br />
我們將 base_url 這個設定值設定正確。<br />
（類似系統的路徑，之後會被Codeigniter調用。）</p>
<pre class="brush: php">/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
|	http://example.com/
|
*/
$config['base_url']	= "http://localhost/ci/"; //這是弦也本機測試的網址
</pre>
<p>那麼，打開你的 Codeigniter 就會看見預設的歡迎頁面了！</p>
<p>而這個歡迎頁面是由 application/views/welcome_message.php 產生的。<br />
其 Controller 則是 application/controllers/welcome.php</p>
<p>接下來，我們要自己產生一個頁面。<br />
但在此之前，我們需要理解一下 MVC 是什麼，還有套用 MVC 架構的 Framework 又是什麼。<br />
MVC 是 Model, View, Controller 三個字的縮寫。<br />
Model &#8211; 資料層（資料處理）<br />
View &#8211; 視圖層（畫面顯示）<br />
Controller &#8211; 控制層（程式處理）<br />
註：弦也印象不佳，沒有記錯應是如上。各位可以到 Wiki 上查詢正確的資訊。</p>
<p>簡單來說，我們把程式分成三個部份。<br />
資料處理（讀取資料、寫入資料等）、畫面顯示（產生畫面）、程式處理（登入、登出、計算等）</p>
<p>而 Framework 則是一些好用的功能集合，簡單說就是類似 WordPress 的 Plugin 功能，在需要時可以去呼叫來使用。<br />
使用 MVC 架構的 Framework 就是兩個合體拉（含糊不清</p>
<p>接下來我們說明一下 Router 這個東西。<br />
根據弦也使用 Codeigniter 和 ZendFramework 的經驗。</p>
<p>為了確立 MVC 這個架構不會亂掉，所以我們把每個頁面要呼叫的 Controller 用一個叫做 Router 的程式去分配。<br />
例如：/blog 分配給 BlogController.php 控制，把 /bbs 分配給 BbsController.php 去控制。<br />
如此一來，就不會混在一起。<br />
（當然也有例外情況，像是自己改寫 Router 的作法。）<br />
最最最簡單的去說他，那就是「發出指令的傢伙」<br />
最後就是 Controller 收到指令，去做他該做的事情。<br />
（就這樣，開始唬爛……）</p>
<p>嘛，既然現在有 Router 去幫你分派每個頁面該被呼叫的 Controller, 那麼就可以無視新增檔案了！<br />
我們直接到 application/controllers 裡面新增一個 hello.php 檔案吧！<br />
（新增這個檔案，只要寫好對應的 Controller 打開 /hello 的時候，就能產生頁面摟！）</p>
<p>hello.php 內容</p>
<pre class="brush:php">&lt;?php
class Hello extends Controller //檔名為 hello.php 時，類別名稱一定要是 Hello (首字大寫)
{
  functon __construct() //建構子，在 PHP5 之後才支援。
  {
    parent::Controller(); //確認父類別為 Controller
  }

  function index(){
    echo 'Hello World!';
  }
}
</pre>
<p>接著打開 http://localhost/ci/hello , 是否看到 Hello World! 字樣了呢？<br />
（上面是弦也的測試網址，各位要換成自己的喔！）</p>
<p>註：被 include 的檔案，結尾是不用 ?&gt; 的！</p>
<p>最後，我們再來學習一下 View 的使用。<br />
（Model 比較複雜，我們晚點再去玩他～）</p>
<p>到 application/views 下新增一個 hello_output.php<br />
hello_output.php 內容</p>
<pre class="brush: html, php">&lt;html&gt;
&lt;head&gt;Hello World!&lt;/head&gt;
&lt;body&gt;
Hello Codeigniter!
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>為了避免大家混淆，就用 hello_output.php 來和 hello.php 區分。</p>
<p>回到 application/controllers 編輯 hello.php 為下面的內容</p>
<pre class="brush:php">&lt;?php
class Hello extends Controller //檔名為 hello.php 時，類別名稱一定要是 Hello (首字大寫)
{
  functon __construct() //建構子，在 PHP5 之後才支援。
  {
    parent::Controller(); //確認父類別為 Controller
  }

  function index(){
    $this-&gt;load-&gt;view('hello_output'); //使用 Views 的 hello_output.php 檔案當作顯示
  }
}
</pre>
<p>那麼再次打開 /hello 是否出現 hello_output.php 的畫面了呢？</p>
<p>這就是，我們與 Codeigniter 的第一次接觸！<br />
註：Controller 的 index 方法是預設的首頁。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.frost.tw/code/poston-2011-01-17/postid-949/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Framework 的一天</title>
		<link>http://blog.frost.tw/code/poston-2011-01-16/postid-948</link>
		<comments>http://blog.frost.tw/code/poston-2011-01-16/postid-948#comments</comments>
		<pubDate>Sun, 16 Jan 2011 11:14:14 +0000</pubDate>
		<dc:creator>蒼時弦や</dc:creator>
				<category><![CDATA[程式語言]]></category>
		<category><![CDATA[BackPress]]></category>
		<category><![CDATA[Codeigniter]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[程式]]></category>

		<guid isPermaLink="false">http://blog.frost.tw/?p=948</guid>
		<description><![CDATA[不少會寫PHP的前人都阻止我在老爸的那個Project使用 BackPress 來開發。 所以，我只好未雨綢繆先想好自己 DIY 和使用 Framework 的方案拉！ （不過前人建議使用Framework來開發～） 而我就實際親身體驗了一下 ZendFramework 以及 Codeigniter 兩款。 無視 CakePHP 的原因，還是因為他真的很慢…… 但，在運作 Codeigniter 簡單輸出時，就在我電腦跑上 0.1 秒左右。 看起來跟 Discuz 這類架站機的基本效能就有差了！ 不過，現在電腦CPU越來越強，應該是影響不大拉！ （畢竟這麼多有名網站使用Framework也都一樣很順暢～） 在我比較 Zend Framework 和 Codeigniter 之後，很快的得到一個結論。 Zend Framework 功能很強大，但是不好理解。 Codeigniter 功能不多，可是卻非常有親和力。 就這點而言，我個人偏向選擇 Codeigniter &#8230; <a href="http://blog.frost.tw/code/poston-2011-01-16/postid-948">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>不少會寫PHP的前人都阻止我在老爸的那個Project使用 BackPress 來開發。<br />
所以，我只好未雨綢繆先想好自己 DIY 和使用 Framework 的方案拉！<br />
（不過前人建議使用Framework來開發～）</p>
<p>而我就實際親身體驗了一下 ZendFramework 以及 Codeigniter 兩款。<br />
無視 CakePHP 的原因，還是因為他真的很慢……<br />
<span id="more-948"></span><br />
但，在運作 Codeigniter 簡單輸出時，就在我電腦跑上 0.1 秒左右。<br />
看起來跟 Discuz 這類架站機的基本效能就有差了！</p>
<p>不過，現在電腦CPU越來越強，應該是影響不大拉！<br />
（畢竟這麼多有名網站使用Framework也都一樣很順暢～）</p>
<p>在我比較 Zend Framework 和 Codeigniter 之後，很快的得到一個結論。<br />
Zend Framework 功能很強大，但是不好理解。<br />
Codeigniter 功能不多，可是卻非常有親和力。</p>
<p>就這點而言，我個人偏向選擇 Codeigniter 當作我的 Framework 學習方向。<br />
雖然沒有像 ZendFramework 有支援 Dojo 這類 JS Framework 不過在 2.0 時將會支援 jQuery 相關物件。<br />
這對我來說是個好消息，因為我在前端的 JavaScript 正好使用 jQuery 來輔助。</p>
<p>不過在使用這些 Framework 時，我同時也對 Licences 的問題感到好奇。<br />
畢竟這攸關著商業使用，不過 Framework 似乎比較偏向 MIT 而非 GPL 的樣子。<br />
（短期內大概是可以安心了！）</p>
<p>而我選擇 Codeigniter 的理由，其實有好幾個。<br />
一個是因為輕巧、好懂。<br />
再來就是他的 Object 和 ZendFramework 比較起來，比較好記。<br />
像 Zend 的 Controller 還要叫做 ActionController （一看就知道肯定有其他好朋友）<br />
但 Codeigniter 卻明瞭的叫做 Controller （親切好多阿！）</p>
<p>不過 Codeigniter 的 Route 機制我就不是很喜歡了……<br />
（ZendFramework 沒搞懂……）<br />
所幸 Codeigniter 提供不少方法去自訂，不然我會瘋掉吧！</p>
<p>但，使用Framework卻和我的Project的部份功能衝突。<br />
這點需要好好思考以及看看網路上討論者的建議，才能做最後決定。<br />
（衝突部份是我將會給使用者自訂Themes, 但 Views 層面預設會鎖住這個的彈性。）</p>
<p>註：Codeigniter 預設沒有 Auth和Role, 挺適合頭痛一陣子的（苦笑</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.frost.tw/code/poston-2011-01-16/postid-948/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>12月 ~ 1月程式隨手札記</title>
		<link>http://blog.frost.tw/life/poston-2011-01-14/postid-944</link>
		<comments>http://blog.frost.tw/life/poston-2011-01-14/postid-944#comments</comments>
		<pubDate>Fri, 14 Jan 2011 11:08:53 +0000</pubDate>
		<dc:creator>蒼時弦や</dc:creator>
				<category><![CDATA[生活雜記]]></category>
		<category><![CDATA[BackPress]]></category>
		<category><![CDATA[bbPress]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[架站]]></category>
		<category><![CDATA[程式]]></category>

		<guid isPermaLink="false">http://blog.frost.tw/?p=944</guid>
		<description><![CDATA[最近在程式上沒什麼新進展，所以就來回顧一下這一個半月的程式狀況。 概觀來看，又是一個很豐富的生活阿！ 但，我的設計到底去哪裡了（拭淚 不過我想，應該很快就有機會多多練習了～ （畢竟我現在除了看程式外，就去吸收設計方面的資訊。） 首先大概是十一、十二月左右，開始接觸 bbPress 吧！ 那時剛好老師請我幫忙弄學校的 Project 因此又開始回溫 PHP 了！ （在此之前都是與 Java 為伍……） 而在 bbPress 的開發上，感受到了 -Press 系列（bbPress, WordPress）的 Plugin 系統強大。 與 Discuz 相比，我猜 Press 的運行速度會略慢（整個架構都是以 Plugin 為核心，需要做很多的 Function 處理） 不過在可變性的優勢，就是 Discuz 遠遠所不能及。 雖然 Discuz 的 Core &#8230; <a href="http://blog.frost.tw/life/poston-2011-01-14/postid-944">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>最近在程式上沒什麼新進展，所以就來回顧一下這一個半月的程式狀況。<br />
概觀來看，又是一個很豐富的生活阿！</p>
<p>但，我的設計到底去哪裡了（拭淚<br />
不過我想，應該很快就有機會多多練習了～<br />
（畢竟我現在除了看程式外，就去吸收設計方面的資訊。）<br />
<span id="more-944"></span><br />
首先大概是十一、十二月左右，開始接觸 bbPress 吧！<br />
那時剛好老師請我幫忙弄學校的 Project 因此又開始回溫 PHP 了！<br />
（在此之前都是與 Java 為伍……）</p>
<p>而在 bbPress 的開發上，感受到了 -Press 系列（bbPress, WordPress）的 Plugin 系統強大。<br />
與 Discuz 相比，我猜 Press 的運行速度會略慢（整個架構都是以 Plugin 為核心，需要做很多的 Function 處理）<br />
不過在可變性的優勢，就是 Discuz 遠遠所不能及。</p>
<p>雖然 Discuz 的 Core 在 X1 推出後，也逐漸有越來越多的 Template Hook 可以插入區塊。<br />
但相較 bbPress 的 Fliter 機制，就遜色很多。<br />
（一個是自訂，一個是套用系統函式者就能調整。）</p>
<p>接下來就是一月初，老爸和我說完我將要做的 Project 後。<br />
我接觸了兩個東西，一個是 BackPress 另一個是插花的 Conduit Toolbar 了！</p>
<p>首先來簡單過 Conduit Toolbar 的功能。<br />
其整體架構很簡單，但多了 API 可運用（嚴格來說是可以插入網頁）<br />
但，又有 JavaScript 與其他配，讓他多了更多變化（Refresh機制）</p>
<p>這個 Refresh 機制可以讓 Toolbar 刷新，只要搭配 PHP, Perl, ASP, JSP 等 CGI 程式就能做出變化。<br />
（登入 &gt; 刷新 &gt; 請求網頁[Session/Cookie紀錄已登入] &gt; 回應新頁面[因為登入關係顯示的圖示增加]）</p>
<p>最後就是 BackPress 這個部份（WordPress, bbPress 的 Core 技術）<br />
整體上來看，其實是從 WordPress 將一些優秀的 Function, Class 抽取出來。<br />
並且加以整合後發布的 PHP Library ，但其功能強大可以稱做一個小型的 Framework 了！</p>
<p>而弦也個人認為 BackPress 最有特色的地方莫過於其 Database 的強化。<br />
原本 WP 僅支援單一資料庫，但在 BackPress 則追加了 Multi DB 的 Class 在其中。<br />
而 Plugin API 也是一項優秀的處理。<br />
（如同前面所述，效能可能稍差，但擁有極強的延展性。）</p>
<p>以上就是這一個半月在程式上的經歷。<br />
希望往後還能繼續分享各種在程式、設計上的經驗給大家。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.frost.tw/life/poston-2011-01-14/postid-944/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BackPress 的 Multiple Database 物件</title>
		<link>http://blog.frost.tw/code/poston-2011-01-12/postid-939</link>
		<comments>http://blog.frost.tw/code/poston-2011-01-12/postid-939#comments</comments>
		<pubDate>Wed, 12 Jan 2011 11:19:44 +0000</pubDate>
		<dc:creator>蒼時弦や</dc:creator>
				<category><![CDATA[程式語言]]></category>
		<category><![CDATA[BackPress]]></category>
		<category><![CDATA[bbPress]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[程式]]></category>
		<category><![CDATA[網站]]></category>

		<guid isPermaLink="false">http://blog.frost.tw/?p=939</guid>
		<description><![CDATA[說起來，弦也為了學測完畢的 Project 思考了幾天 Database 的處理方案。 就整理方便等概念來看，多用戶系統還是有分開的資料庫會比較好。 那麼，連接資料庫時，除了主資料庫（會員資料）之外，也要有用戶資料庫（用戶網站資料）來連接。 不過，一般的 MySQL Class 都是以單資料庫連接為準。 就像 Discuz 的 MySQL 就是以單資料庫為主。 那麼，假使我需要多資料庫，該怎麼辦呢？ 很幸運的，在 BackPress 的 Library 中，將這項功能實做。 而且處理的方法也是非常的優秀。 弦也從沒想過還可以利用此種方式進行「多資料庫」的處理。 首先我們來看看 BackPress 的 BPDB_Multi 物件進行多資料庫處理的情況。 （以 bbPress 的資料表當作連接範例，弦也電腦剛好安裝挺多bbPress論壇。） &#60;?php if ( !defined( 'BACKPRESS_PATH' ) ) { &#8230; <a href="http://blog.frost.tw/code/poston-2011-01-12/postid-939">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>說起來，弦也為了學測完畢的 Project 思考了幾天 Database 的處理方案。<br />
就整理方便等概念來看，多用戶系統還是有分開的資料庫會比較好。</p>
<p>那麼，連接資料庫時，除了主資料庫（會員資料）之外，也要有用戶資料庫（用戶網站資料）來連接。<br />
不過，一般的 MySQL Class 都是以單資料庫連接為準。<br />
就像 Discuz 的 MySQL 就是以單資料庫為主。</p>
<p>那麼，假使我需要多資料庫，該怎麼辦呢？<br />
<span id="more-939"></span><br />
很幸運的，在 BackPress 的 Library 中，將這項功能實做。<br />
而且處理的方法也是非常的優秀。</p>
<p>弦也從沒想過還可以利用此種方式進行「多資料庫」的處理。</p>
<p>首先我們來看看 BackPress 的 BPDB_Multi 物件進行多資料庫處理的情況。<br />
（以 bbPress 的資料表當作連接範例，弦也電腦剛好安裝挺多bbPress論壇。）</p>
<pre class="brush: php">&lt;?php
if ( !defined( 'BACKPRESS_PATH' ) ) {
 define( 'BACKPRESS_PATH', './backpress/' );
}

require_once( BACKPRESS_PATH . 'functions.core.php' );
require_once( BACKPRESS_PATH . 'functions.compat.php' );
require_once( BACKPRESS_PATH . 'functions.formatting.php' );

include( BACKPRESS_PATH . 'class.bpdb-multi.php' );

$db = new BPDB_Multi(
 array(
 'name' =&gt; 'bbpress',
 'user' =&gt; 'root',
 'password' =&gt; 'rootpassword',
 'host' =&gt; 'localhost',
 'charset' =&gt; 'utf8',
 'collate' =&gt; false
 )
);

$db-&gt;add_db_server(
 'mms',
 array(
 'name' =&gt; 'mms',
 'user' =&gt; 'root',
 'password' =&gt; 'rootpassword',
 'host' =&gt; 'localhost',
 'charset' =&gt; 'utf8',
 'collate' =&gt; false
 )
);

$db-&gt;add_db_table( 'mms', 'bb_users' );
$db-&gt;add_db_table( 'global', 'bb_topics' );

print_r( $db );
echo '&lt;br /&gt;---&lt;br /&gt;';
print_r( $db-&gt;get_results('SELECT topic_title FROM bb_topics LIMIT 0,10;'));
echo '&lt;br /&gt;---&lt;br /&gt;';
print_r( $db-&gt;get_results('SELECT user_login FROM bb_users LIMIT 0,10;'));
echo '&lt;br /&gt;---&lt;br /&gt;';
print_r( $db );
?&gt;</pre>
<p>以上程式碼將會在不同時機抓取不同網站的資料。<br />
抓取會員登入帳號時，則會連接 Global 這個資料庫（預設）<br />
而抓取文章主題時，則會連接我們新增的 mms 這個資料庫。</p>
<p>而我們分別在開始和結束時將 Object 印出來，觀察 MySQL Connect 的狀況。</p>
<p>經過測試後，確實分別連接兩個資料庫進行查詢。<br />
而除了 Global 預設自動連接外，其他資料庫要有查詢會建立連接。<br />
（避免連接過多消耗資源）</p>
<p>這個 Multiple Database Object 除了重新調整了幾個 BPDB 的方法外。<br />
就是新增了 add_db_table 這個方法。</p>
<p>NULL add_db_table( String DB_NAME, String Table_NAME );</p>
<p>簡單來說，就是給入索引讓 Multi DB 在選擇連接的資料庫時，知道該選取哪一個。<br />
假使沒有可以選取，則以預設為主。</p>
<p>那麼，在開發多用戶系統時，就變得非常輕鬆了！<br />
（僅需將用戶的Table傳入，搭配上查詢的 prefix 切換，就可以做到。）</p>
<p>註：bbPress 預設是使用 BPDB_Multi 物件，因此要將其改良成多資料庫，應該是不難的！</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.frost.tw/code/poston-2011-01-12/postid-939/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

