<?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; smarty</title>
	<atom:link href="http://blog.wabow.com/archives/tag/smarty/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.wabow.com</link>
	<description>Wabow Information Inc. Blog</description>
	<lastBuildDate>Fri, 21 May 2010 15:11:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>[Smarty]如何使用自訂函式</title>
		<link>http://blog.wabow.com/archives/663</link>
		<comments>http://blog.wabow.com/archives/663#comments</comments>
		<pubDate>Fri, 03 Apr 2009 07:26:48 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
				<category><![CDATA[技術分享]]></category>
		<category><![CDATA[smarty]]></category>

		<guid isPermaLink="false">http://blog.wabow.com/?p=663</guid>
		<description><![CDATA[緣由 當我們在撰寫smarty程式時，常常會因為特別的需求而需要使用到自定的函式，那個要如何讓smarty"認得"自訂函式然後可以在樣板頁套用呢?smarty有提供register_modifier的用法，讓我們來看看要怎麼使用吧! register_modifier 官方文件：http://www.smarty.net/manual/en/api.register.modifier.php 程式碼 public function indexAction&#40;&#41; &#123; .... $smarty = $this-&#62;view-&#62;getEngine&#40;&#41;; $smarty-&#62;register_modifier&#40;'self_functuion', 'selfFunction'&#41;; .... &#125; 解說 程式中的第一行表示我們先利用getEngine方式抓取一個smarty物件；而第二行中的register_modifier的用法為： register_modifier('樣板頁使用的函式名稱','函式真實名稱'); 這樣設定後在樣板用就可以使用我們自訂的函式，是不是很容易呢?雖然這是一種暫時性的用法，不過在一些小地方上的處理上卻不失為快速簡便的用法。 附註 程式碼為wacow framework架構下的寫法。範例中-&#62;view等同於在smarty的-&#62;assign，也就是要把值塞到樣板頁的變數呈現在頁面上；至於smarty的用法可參照jace大師的教學網頁，這裡詳細描述了smarty的架構觀念以及程式的寫法，可以詳加研究。]]></description>
			<content:encoded><![CDATA[<p><H3>緣由</H3><br />
當我們在撰寫smarty程式時，常常會因為特別的需求而需要使用到自定的函式，那個要如何讓smarty"認得"自訂函式然後可以在樣板頁套用呢?smarty有提供register_modifier的用法，讓我們來看看要怎麼使用吧!<br />
<span id="more-663"></span></p>
<p><H3>register_modifier</H3><br />
官方文件：<a href="http://www.smarty.net/manual/en/api.register.modifier.php">http://www.smarty.net/manual/en/api.register.modifier.php</a></p>
<p><H3>程式碼</H3></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #339933;">....</span>
<span style="color: #000088;">$smarty</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getEngine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">register_modifier</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'self_functuion'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'selfFunction'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">....</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><H3>解說</H3><br />
程式中的第一行表示我們先利用getEngine方式抓取一個smarty物件；而第二行中的register_modifier的用法為：<br />
<strong>register_modifier('樣板頁使用的函式名稱','函式真實名稱');</strong><br />
這樣設定後在樣板用就可以使用我們自訂的函式，是不是很容易呢?雖然這是一種暫時性的用法，不過在一些小地方上的處理上卻不失為快速簡便的用法。</p>
<p><H3>附註</H3><br />
程式碼為wacow framework架構下的寫法。範例中-&gt;view等同於在smarty的-&gt;assign，也就是要把值塞到樣板頁的變數呈現在頁面上；至於smarty的用法可參照jace大師的<a href="http://blog.roodo.com/jaceju/archives/175925.html">教學網頁</a>，這裡詳細描述了smarty的架構觀念以及程式的寫法，可以詳加研究。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.wabow.com/archives/663/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Smarty]樣板頁中使用php函數的用法</title>
		<link>http://blog.wabow.com/archives/652</link>
		<comments>http://blog.wabow.com/archives/652#comments</comments>
		<pubDate>Fri, 03 Apr 2009 06:42:56 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
				<category><![CDATA[技術分享]]></category>
		<category><![CDATA[smarty]]></category>

		<guid isPermaLink="false">http://blog.wabow.com/?p=652</guid>
		<description><![CDATA[一般我們在smarty樣版中如果要在顯示的資料使用php函式時，如果是只有一個參數的函式比如說去空白的trim會寫成： sample 1 &#60;% $Row-&#62;colname&#124;trim %&#62; 那如果使用像iconv這樣有三個參數的函式該怎麼寫呢?如果寫成： sample 2 &#60;% $Row-&#62;colname&#124;iconv:'utf-8':'big5' %&#62; 一執行就會發現顯示error訊息。 因此研究一下就會發現到，其實在smarty樣板頁的套用函式用法中，以sample 1來說，trim的前面$Row-&#62;colname其實就是trim的第一個參數，中間用&#124;這個符號串接； 那假使要使用像iconv有三個參數函式的話，就要寫成： sample3 &#60;% 'utf-8'&#124;iconv:'big5':$Row-&#62;colname %&#62; 也就是 函式第一個參數&#124;函式:第二個參數:第三個參數。sample 3中會把colname的值從utf-8格式轉換成Big5。]]></description>
			<content:encoded><![CDATA[<p>一般我們在smarty樣版中如果要在顯示的資料使用php函式時，如果是只有一個參數的函式比如說去空白的<a href="http://tw.php.net/manual/en/function.trim.php">trim</a>會寫成：<br />
<span id="more-652"></span><br />
sample 1</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;%</span> <span style="color: #000088;">$Row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">colname</span><span style="color: #339933;">|</span>trim <span style="color: #000000; font-weight: bold;">%&gt;</span></pre></div></div>

<p>那如果使用像<a href="http://tw2.php.net/manual/en/function.iconv.php">iconv</a>這樣有三個參數的函式該怎麼寫呢?如果寫成：<br />
sample 2</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;%</span> <span style="color: #000088;">$Row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">colname</span><span style="color: #339933;">|</span>iconv<span style="color: #339933;">:</span><span style="color: #0000ff;">'utf-8'</span><span style="color: #339933;">:</span><span style="color: #0000ff;">'big5'</span> <span style="color: #000000; font-weight: bold;">%&gt;</span></pre></div></div>

<p>一執行就會發現顯示error訊息。<br />
因此研究一下就會發現到，其實在smarty樣板頁的套用函式用法中，以sample 1來說，trim的前面$Row-&gt;colname其實就是trim的第一個參數，中間用|這個符號串接；<br />
那假使要使用像iconv有三個參數函式的話，就要寫成：<br />
sample3</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;%</span> <span style="color: #0000ff;">'utf-8'</span><span style="color: #339933;">|</span>iconv<span style="color: #339933;">:</span><span style="color: #0000ff;">'big5'</span><span style="color: #339933;">:</span><span style="color: #000088;">$Row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">colname</span> <span style="color: #000000; font-weight: bold;">%&gt;</span></pre></div></div>

<p>也就是<br />
<strong>函式第一個參數|函式:第二個參數:第三個參數</strong>。sample 3中會把colname的值從utf-8格式轉換成Big5。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.wabow.com/archives/652/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
