<?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>Life &#187; smarty</title>
	<atom:link href="http://life.co-hey.com/tag/smarty/feed/" rel="self" type="application/rss+xml" />
	<link>http://life.co-hey.com</link>
	<description></description>
	<lastBuildDate>Tue, 17 Jan 2012 08:15:38 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>color me shopにページャーをつける</title>
		<link>http://life.co-hey.com/2010/07/color-me-shop%e3%81%ab%e3%83%9a%e3%83%bc%e3%82%b8%e3%83%a3%e3%83%bc%e3%82%92%e3%81%a4%e3%81%91%e3%82%8b/</link>
		<comments>http://life.co-hey.com/2010/07/color-me-shop%e3%81%ab%e3%83%9a%e3%83%bc%e3%82%b8%e3%83%a3%e3%83%bc%e3%82%92%e3%81%a4%e3%81%91%e3%82%8b/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 00:00:57 +0000</pubDate>
		<dc:creator>co-hey</dc:creator>
				<category><![CDATA[web & pc]]></category>
		<category><![CDATA[ec]]></category>
		<category><![CDATA[smarty]]></category>

		<guid isPermaLink="false">http://life.co-hey.com/?p=726</guid>
		<description><![CDATA[color me shopをいじる機会があったので、今回作ったページャーをご紹介。 テンプレートは、smartyなので馴染みがあり、やりやすかったです。 目指す表示はこんな感じ > 1 2 3 4 5 6 7 8 9 1 [...]]]></description>
			<content:encoded><![CDATA[<p>
color me shopをいじる機会があったので、今回作ったページャーをご紹介。<br />
テンプレートは、smartyなので馴染みがあり、やりやすかったです。<br />
<br />
目指す表示はこんな感じ<br />
<< 前のページへ 1 ・・ 4 5 6 ・・・ 10 次のページへ >><br />
<br />

<div class="wp_codebox"><table><tr id="p7262"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
</pre></td><td class="code" id="p726code2"><pre class="php" style="font-family:Osaka-mono,monospace;">   <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pnavi&quot;</span><span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span><span style="color: #339933;">*</span> 現在表示中のページ数をcurrent_pageに設定 <span style="color: #339933;">*</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">if</span> <span style="color: #000088;">$smarty</span><span style="color: #339933;">.</span>get<span style="color: #339933;">.</span>page <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;&lt;</span><span style="color: #009900;">&#123;</span> assign <span style="color: #000000; font-weight: bold;">var</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;current_page&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;&lt;</span><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;&lt;</span><span style="color: #009900;">&#123;</span> assign <span style="color: #000000; font-weight: bold;">var</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;current_page&quot;</span> value<span style="color: #339933;">=</span><span style="color: #000088;">$smarty</span><span style="color: #339933;">.</span>get<span style="color: #339933;">.</span>page <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;&lt;</span><span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
&nbsp;
&nbsp;
   <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span><span style="color: #339933;">*</span> 前のページがある場合は、リンク化する <span style="color: #339933;">*</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span> <span style="color: #000088;">$productlist_prev_page</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;<span style="color: #006699; font-weight: bold;">{$productlist_prev_page}</span>&gt;&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Page &lt;{<span style="color: #006699; font-weight: bold;">$current_page</span>-1}&gt;&quot;</span><span style="color: #339933;">&gt;&lt;&lt;</span> 前のページへ<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;</span><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;&amp;</span>nbsp<span style="color: #339933;">;&lt;&lt;</span> 前のページへ<span style="color: #339933;">&amp;</span>nbsp<span style="color: #339933;">;&lt;</span><span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span><span style="color: #339933;">*</span> ページ表示数で商品数を割り、ページ数を算出 <span style="color: #339933;">*</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span>math equation<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;ceil(<span style="color: #006699; font-weight: bold;">$productlist_num</span>/12)&quot;</span> assign<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;max_page&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span>math equation<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$current_page</span>-1&quot;</span> assign<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;bef_page&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span>math equation<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$current_page</span>+1&quot;</span> assign<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;aft_page&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span> assign <span style="color: #000000; font-weight: bold;">var</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;page_flg&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;0&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span>section name<span style="color: #339933;">=</span>pager loop<span style="color: #339933;">=</span><span style="color: #000088;">$max_page</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span><span style="color: #339933;">*</span> 表示中のページに、専用の<span style="color: #000000; font-weight: bold;">class</span>を付与する <span style="color: #339933;">*</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">if</span> <span style="color: #000088;">$smarty</span><span style="color: #339933;">.</span>section<span style="color: #339933;">.</span>pager<span style="color: #339933;">.</span>iteration <span style="color: #339933;">==</span> <span style="color: #000088;">$current_page</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
       <span style="color: #339933;">&lt;</span>span <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;here&quot;</span><span style="color: #339933;">&gt;&lt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$smarty</span><span style="color: #339933;">.</span>section<span style="color: #339933;">.</span>pager<span style="color: #339933;">.</span>iteration <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;&lt;/</span>span<span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
       <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">if</span> <span style="color: #000088;">$productlist_sort_now</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;p&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
          <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span> assign <span style="color: #000000; font-weight: bold;">var</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;page_url&quot;</span>  value<span style="color: #339933;">=</span><span style="color: #000088;">$productlist_sort_price</span><span style="color: #339933;">|</span>cat<span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;&amp;page=&quot;</span><span style="color: #339933;">|</span>cat<span style="color: #339933;">:</span><span style="color: #000088;">$smarty</span><span style="color: #339933;">.</span>section<span style="color: #339933;">.</span>pager<span style="color: #339933;">.</span>iteration <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
       <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #000088;">$productlist_sort_now</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;n&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
          <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span> assign <span style="color: #000000; font-weight: bold;">var</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;page_url&quot;</span>  value<span style="color: #339933;">=</span><span style="color: #000088;">$productlist_sort_new</span><span style="color: #339933;">|</span>cat<span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;&amp;page=&quot;</span><span style="color: #339933;">|</span>cat<span style="color: #339933;">:</span><span style="color: #000088;">$smarty</span><span style="color: #339933;">.</span>section<span style="color: #339933;">.</span>pager<span style="color: #339933;">.</span>iteration <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
       <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
          <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span> assign <span style="color: #000000; font-weight: bold;">var</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;page_url&quot;</span>  value<span style="color: #339933;">=</span><span style="color: #000088;">$productlist_sort_def</span><span style="color: #339933;">|</span>cat<span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;&amp;page=&quot;</span><span style="color: #339933;">|</span>cat<span style="color: #339933;">:</span><span style="color: #000088;">$smarty</span><span style="color: #339933;">.</span>section<span style="color: #339933;">.</span>pager<span style="color: #339933;">.</span>iteration <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
       <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span> <span style="color: #339933;">/</span><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
&nbsp;
       <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">if</span> <span style="color: #000088;">$max_page</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">7</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
         <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span><span style="color: #339933;">*</span> <span style="color: #cc66cc;">1</span>ページ目と最終ページ、現在表示しているページの前後<span style="color: #cc66cc;">1</span>ページをリンクとして表示 <span style="color: #339933;">*</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
         <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">if</span> <span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$smarty</span><span style="color: #339933;">.</span>section<span style="color: #339933;">.</span>pager<span style="color: #339933;">.</span>iteration<span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #000088;">$bef_page</span><span style="color: #339933;">,</span> <span style="color: #000088;">$aft_page</span><span style="color: #339933;">,</span> <span style="color: #000088;">$max_page</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
         <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span> assign <span style="color: #000000; font-weight: bold;">var</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;page_flg&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;0&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
         <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;<span style="color: #006699; font-weight: bold;">{$page_url}</span>&gt;&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Page &lt;{<span style="color: #006699; font-weight: bold;">$smarty</span>.section.pager.iteration }&gt;&quot;</span><span style="color: #339933;">&gt;&lt;</span><span style="color: #009900;">&#123;</span> <span style="color: #000088;">$smarty</span><span style="color: #339933;">.</span>section<span style="color: #339933;">.</span>pager<span style="color: #339933;">.</span>iteration <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;&lt;/</span>a<span style="color: #339933;">&gt;</span>
         <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #000088;">$page_flg</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;0&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
           <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span> assign <span style="color: #000000; font-weight: bold;">var</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;page_flg&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
           ・・・
         <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span> <span style="color: #339933;">/</span><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
       <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
         <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;<span style="color: #006699; font-weight: bold;">{$page_url}</span>&gt;&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Page &lt;{<span style="color: #006699; font-weight: bold;">$smarty</span>.section.pager.iteration }&gt;&quot;</span><span style="color: #339933;">&gt;&lt;</span><span style="color: #009900;">&#123;</span> <span style="color: #000088;">$smarty</span><span style="color: #339933;">.</span>section<span style="color: #339933;">.</span>pager<span style="color: #339933;">.</span>iteration <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;&lt;/</span>a<span style="color: #339933;">&gt;</span>
       <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span> <span style="color: #339933;">/</span><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span> <span style="color: #339933;">/</span><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span>section<span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span><span style="color: #339933;">*</span> 次のページがある場合は、リンク化する <span style="color: #339933;">*</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span> <span style="color: #000088;">$productlist_next_page</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;<span style="color: #006699; font-weight: bold;">{$productlist_next_page}</span>&gt;&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Page &lt;{<span style="color: #006699; font-weight: bold;">$current_page</span>+1}&gt;&quot;</span><span style="color: #339933;">&gt;</span>次のページへ <span style="color: #339933;">&gt;&gt;&lt;/</span>a<span style="color: #339933;">&gt;&lt;</span><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;&amp;</span>nbsp<span style="color: #339933;">;</span>次のページへ <span style="color: #339933;">&gt;&gt;&amp;</span>nbsp<span style="color: #339933;">;&lt;</span><span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;</span>    
    <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<br />
</p>

<a href="http://twitter.com/?status=RT%20%40%3A%20color%20me%20shop%E3%81%AB%E3%83%9A%E3%83%BC%E3%82%B8%E3%83%A3%E3%83%BC%E3%82%92%E3%81%A4%E3%81%91%E3%82%8B%20-%20Life%20http%3A%2F%2Ftinyurl.com%2F2dl36me" class="tweet-this" ><img src="http://life.co-hey.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="つぶやく" alt="つぶやく" /></a>]]></content:encoded>
			<wfw:commentRss>http://life.co-hey.com/2010/07/color-me-shop%e3%81%ab%e3%83%9a%e3%83%bc%e3%82%b8%e3%83%a3%e3%83%bc%e3%82%92%e3%81%a4%e3%81%91%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend_ViewでSmartyをラップする６</title>
		<link>http://life.co-hey.com/2008/01/zend_viewsmarty_5/</link>
		<comments>http://life.co-hey.com/2008/01/zend_viewsmarty_5/#comments</comments>
		<pubDate>Thu, 31 Jan 2008 13:55:54 +0000</pubDate>
		<dc:creator>co-hey</dc:creator>
				<category><![CDATA[framework]]></category>
		<category><![CDATA[smarty]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://life.co-hey.com//wp/?p=80</guid>
		<description><![CDATA[今回は、やりたいことの２つ目、３つ目に入っていた 2.プログラムが必要ない場合は...]]></description>
			<content:encoded><![CDATA[<p>
今回は、やりたいことの２つ目、３つ目に入っていた<br />
2.プログラムが必要ない場合は、Actionコントローラーを書きたくない<br />
　（Actionメソッドがなくても、テンプレートが表示されるようにしたい）<br />
3.テンプレートもないURLが指定されたら、トップページなど指定のURLに遷移させたい<br />
を実現する方法です。<br />
<br />
Zendは、初期状態で、ErrorHandlerプラグインというプログラムが有効になっています。<br />
これは、プログラム実行中に、エラーが発生した場合、<br />
ErrorActionコントローラーのerrorActionというメソッドをよびだしてくれます。<br />
<br />
そこで、コントローラークラスが見つからなかった場合、<br />
アクションメソッドが見つからなかった場合の判別が可能です。<br />
私が作った、ErrorActionクラスから必要な部分を抜き出したのが以下です。<br />
<br />

<div class="wp_codebox"><table><tr id="p803"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code" id="p80code3"><pre class="php" style="font-family:Osaka-mono,monospace;"><span style="color: #000000; font-weight: bold;">class</span> ErrorController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action
<span style="color: #009900;">&#123;</span>
　<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> errorAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
　<span style="color: #009900;">&#123;</span>
　　<span style="color: #000088;">$errors</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getParam<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error_handler'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
　　<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$errors</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">type</span><span style="color: #009900;">&#41;</span>
　　<span style="color: #009900;">&#123;</span>
　　　<span style="color: #b1b100;">case</span> Zend_Controller_Plugin_ErrorHandler<span style="color: #339933;">::</span><span style="color: #004000;">EXCEPTION_NO_CONTROLLER</span><span style="color: #339933;">:</span>
　　　　<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getParam<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span>
　　　　<span style="color: #009900;">&#123;</span>
　　　　　<span style="color: #000088;">$view</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getHelper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'viewRenderer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
　　　　　<span style="color: #000088;">$view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setNoController</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
　　　　  　　 <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setScriptAction</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getParam<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'controller'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
　　　　<span style="color: #009900;">&#125;</span>
&nbsp;
　　　<span style="color: #b1b100;">case</span> Zend_Controller_Plugin_ErrorHandler<span style="color: #339933;">::</span><span style="color: #004000;">EXCEPTION_NO_ACTION</span><span style="color: #339933;">:</span>
　　　　<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$view</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
　　　　<span style="color: #009900;">&#123;</span>
　　　　　<span style="color: #000088;">$view</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getHelper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'viewRenderer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
　　　　　<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setControllerName</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getParam<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'controller'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
　　　　　<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setActionName</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getParam<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
　　　　<span style="color: #009900;">&#125;</span>
&nbsp;
　　　　<span style="color: #000088;">$template</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getViewBasePathSpec</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getViewScript</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
　　　　<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_readable</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$template</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_redirect<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
　　　　<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
　　　<span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
　　　　<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
　　<span style="color: #009900;">&#125;</span>
　<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<br />
</p>

<a href="http://twitter.com/?status=RT%20%40%3A%20Zend_View%E3%81%A7Smarty%E3%82%92%E3%83%A9%E3%83%83%E3%83%97%E3%81%99%E3%82%8B%EF%BC%96%20-%20Life%20http%3A%2F%2Ftinyurl.com%2Fyjrhpfu" class="tweet-this" ><img src="http://life.co-hey.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="つぶやく" alt="つぶやく" /></a>]]></content:encoded>
			<wfw:commentRss>http://life.co-hey.com/2008/01/zend_viewsmarty_5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend_ViewでSmartyをラップする５</title>
		<link>http://life.co-hey.com/2008/01/zend_viewsmarty_4/</link>
		<comments>http://life.co-hey.com/2008/01/zend_viewsmarty_4/#comments</comments>
		<pubDate>Wed, 30 Jan 2008 09:28:12 +0000</pubDate>
		<dc:creator>co-hey</dc:creator>
				<category><![CDATA[framework]]></category>
		<category><![CDATA[smarty]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://life.co-hey.com//wp/?p=78</guid>
		<description><![CDATA[前回で、Smartyの利用と、ViewRendererヘルパーを利用して、 Sm...]]></description>
			<content:encoded><![CDATA[<p>
<p>前回で、Smartyの利用と、ViewRendererヘルパーを利用して、<br /><br />
Smartyを利用した画面の自動描画が有効になる方法を紹介しました。</p>
<br />
<p>今回は、やりたいことの１つ目にあげていた<br /><br />
1.テンプレートの配置をURLからイメージしやすいようにしたい<br /><br />
ということを実現する方法です。</p>
<br />
<p>この方法を実行するのは、各コントローラーのindexActionのみです。<br /><br />
そこで、このどちらかを記述すればＯＫです。</p>
<br />

<div class="wp_codebox"><table><tr id="p784"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p78code4"><pre class="php" style="font-family:Osaka-mono,monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getHeler</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'viewRenderer'</span><span style="color: #009900;">&#41;</span>
　　 <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setNoController</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
　　 <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setScriptAction</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getControllerName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<br />
<br />
<br />
<p>または</p>
<br />

<div class="wp_codebox"><table><tr id="p785"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p78code5"><pre class="php" style="font-family:Osaka-mono,monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getControllerName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<br />
<br />
<br />
<p>これはどちらも同じ意味になります。</p>
<br />
<p>こうすることで、<br /><br />
http://test.com/aaa/　というＵＲＬでアクセスされた場合、<br /><br />
templates/aaa/index.htmlではなく、templates/aaa.htmlを読み込んでくれます。</p></p>

<a href="http://twitter.com/?status=RT%20%40%3A%20Zend_View%E3%81%A7Smarty%E3%82%92%E3%83%A9%E3%83%83%E3%83%97%E3%81%99%E3%82%8B%EF%BC%95%20-%20Life%20http%3A%2F%2Ftinyurl.com%2Fykxgnuc" class="tweet-this" ><img src="http://life.co-hey.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="つぶやく" alt="つぶやく" /></a>]]></content:encoded>
			<wfw:commentRss>http://life.co-hey.com/2008/01/zend_viewsmarty_4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend_ViewでSmartyをラップする４</title>
		<link>http://life.co-hey.com/2008/01/zend_viewsmarty_3/</link>
		<comments>http://life.co-hey.com/2008/01/zend_viewsmarty_3/#comments</comments>
		<pubDate>Sun, 27 Jan 2008 13:57:24 +0000</pubDate>
		<dc:creator>co-hey</dc:creator>
				<category><![CDATA[framework]]></category>
		<category><![CDATA[smarty]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://life.co-hey.com//wp/?p=76</guid>
		<description><![CDATA[前回の記事で書いたことを試してみました。 私がsmartyとZendを合わせて使...]]></description>
			<content:encoded><![CDATA[<p>
<p>前回の記事で書いたことを試してみました。<br /><br />
私がsmartyとZendを合わせて使う上で、実現したいのは以下</p>
<br />
<p>1.テンプレートの配置をURLからイメージしやすいようにしたい<br /><br />
　http://test.com/aaa/ の場合は、templates/aaa.html<br /><br />
　http://test.com/aaa/bbb/の場合は、templates/aaa/bbb.html</p>
<br />
<p>2.プログラムが必要ない場合は、Actionコントローラーを書きたくない<br /><br />
　（Actionメソッドがなくても、テンプレートが表示されるようにしたい）</p>
<br />
<p>3.テンプレートもないURLが指定されたら、トップページなど指定のURLに遷移させたい</p>
<br />
<p>1.は、renderのnoControllerがtrueのときのテンプレート作成ルールを、<br /><br />
コントローラー名＋指定拡張子とすることで解決。<br /><br />
ただし、render呼び出しの際に、<br /><br />
$this->render(コントローラー名, null, true)<br /><br />
とする必要がありますが、この部分を簡略化できないかが今後の課題です。</p>
<br />
<p>2.はまだ試せてません。しかし、前々回の記事の方法が応用できそうです。<br /><br />
3.も２.と同様に前々回の記事の方法で実現できそうです。</p>
<br />
<p>しかし、前回と同様の方法だと、Zend_Controller_Actionのサブクラスを基底クラスとして<br /><br />
作成することになるので、これはできれば避けたいところです。<br /><br />
会員サイトとかなら、基底クラス作るのはいいのですが、Ｓｍａｒｔｙ使いたいだけで、<br /><br />
基底クラスを作るとなると、ログインセッション管理をやろうと思ったときに、<br /><br />
テンプレートエンジンに関わるファイルを修正することになりかねません。</p>
<br />
<p>index.phpにつぎたした部分は以下です。</p>
<br />

<div class="wp_codebox"><table><tr id="p766"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p76code6"><pre class="php" style="font-family:Osaka-mono,monospace;"><span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zend/Controller/Action/Helper/ViewRenderer.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Custom/View/Smarty.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$view</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_View_Smarty<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$smartyConfig</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$viewHelper</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Controller_Action_Helper_ViewRenderer<span style="color: #009900;">&#40;</span><span style="color: #000088;">$view</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$viewHelper</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setViewBasePathSpec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$smartyConfig</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'template_dir'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
　　　　　 <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setViewSuffix</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'html'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Zend_Controller_Action_HelperBroker<span style="color: #339933;">::</span><span style="color: #004000;">addHelper</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$viewHelper</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<br />
<br />
<br />
<p>$smartyConfigは、Smartyの設定値の配列です。<br /><br />
Custom/View/Smarty.phpは、Zend_View_Interfaceに沿って、<br /><br />
Smarｔｙが使えるようにしたViewクラスです。<br /><br />
中身は、<a href="http://framework.zend.com/manual/ja/zend.view.scripts.html#zend.view.scripts.templates">ここ</a>の最後の方にのっているSmartyラッパークラスと同様です。<br /><br />
ただ、function getScriptPaths()に誤りがあります。<br /><br />
<br />

<div class="wp_codebox"><table><tr id="p767"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p76code7"><pre class="php" style="font-family:Osaka-mono,monospace;"><span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_smarty<span style="color: #339933;">-&gt;</span><span style="color: #004000;">template_dir</span><span style="color: #339933;">;</span>
　　↓
<span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_smarty<span style="color: #339933;">-&gt;</span><span style="color: #004000;">template_dir</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<br />
<br />
とする必要があります。<br /><br />
getScriptPaths()なので、パスが配列で複数取得されることが想定されて、<br /><br />
Zend_Controller_Action_Helper_ViewRendererが作成されているためです。</p>
<br />
<p>これでより少ないソースで、smartyと連携できるようになりました。<br /><br />
より手間を少なくする方法がないか、もうちょっと試してみる予定です。<br /><br />
ViewRendererヘルパーと、ErrorHanderプラグインあたりを組み合わせると、<br /><br />
なんとかなりそうな気がドキュメントを読んでいるとするのですが、どうなんでしょう。<br /><br />
あたりがついたら、試してみます。</p></p>

<a href="http://twitter.com/?status=RT%20%40%3A%20Zend_View%E3%81%A7Smarty%E3%82%92%E3%83%A9%E3%83%83%E3%83%97%E3%81%99%E3%82%8B%EF%BC%94%20-%20Life%20http%3A%2F%2Ftinyurl.com%2Fyleratx" class="tweet-this" ><img src="http://life.co-hey.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="つぶやく" alt="つぶやく" /></a>]]></content:encoded>
			<wfw:commentRss>http://life.co-hey.com/2008/01/zend_viewsmarty_3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend_ViewでSmartyをラップする３</title>
		<link>http://life.co-hey.com/2008/01/zend_viewsmarty_2/</link>
		<comments>http://life.co-hey.com/2008/01/zend_viewsmarty_2/#comments</comments>
		<pubDate>Thu, 24 Jan 2008 19:30:34 +0000</pubDate>
		<dc:creator>co-hey</dc:creator>
				<category><![CDATA[framework]]></category>
		<category><![CDATA[smarty]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://life.co-hey.com//wp/?p=75</guid>
		<description><![CDATA[昨日、ActionコントローラのinitViewをオーバーライドが簡単って 書い...]]></description>
			<content:encoded><![CDATA[<p>
<p>昨日、ActionコントローラのinitViewをオーバーライドが簡単って<br /><br />
書いたばかりですが、こんなドキュメントを見つけました。<br /><br />
別件でヘルパーかプラングインを作ってみようとしてたときです。</p>
<br />
<p><a href="http://framework.zend.com/manual/ja/zend.controller.actionhelpers.html#zend.controller.actionhelper.stockhelpers">ここ</a>の【例 7.10. パスの指定方法の変更】の部分です。</p>
<br />
<p>テンプレートエンジンをSmartyにするだけなら、これがより簡単です。<br /><br />
見つけたとき、軽く衝撃でした。</p>
<br />
<p>Smartyを使いつつ、私がやりたいこと（現在の方法で実現していること)が<br /><br />
この方法を使ったときに実現できて、かつ簡単なら乗り換えようかと。</p>
<br />
<p>結果は、またこのブログに書きたいと思います。</p></p>

<a href="http://twitter.com/?status=RT%20%40%3A%20Zend_View%E3%81%A7Smarty%E3%82%92%E3%83%A9%E3%83%83%E3%83%97%E3%81%99%E3%82%8B%EF%BC%93%20-%20Life%20http%3A%2F%2Ftinyurl.com%2Fylxljox" class="tweet-this" ><img src="http://life.co-hey.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="つぶやく" alt="つぶやく" /></a>]]></content:encoded>
			<wfw:commentRss>http://life.co-hey.com/2008/01/zend_viewsmarty_2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend_ViewでSmartyをラップする２</title>
		<link>http://life.co-hey.com/2008/01/zend_viewsmarty_1/</link>
		<comments>http://life.co-hey.com/2008/01/zend_viewsmarty_1/#comments</comments>
		<pubDate>Wed, 23 Jan 2008 14:07:29 +0000</pubDate>
		<dc:creator>co-hey</dc:creator>
				<category><![CDATA[framework]]></category>
		<category><![CDATA[smarty]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://life.co-hey.com//wp/?p=74</guid>
		<description><![CDATA[ドキュメント読んだり、ソースおったりしているうちに、 Zend_Controll...]]></description>
			<content:encoded><![CDATA[<p>
<p>ドキュメント読んだり、ソースおったりしているうちに、<br /><br />
Zend_Controller_ActionクラスのinitViewをオーバーライドして、<br /><br />
Front Controllerにて、noViewRendererをtrueに設定して、<br /><br />
各アクションの最後に、$this->render()で、画面表示するのが、<br /><br />
一番楽なんじゃないかという結論に達しました。</p>
<br />
<p>重要なのは、initViewの中で、$this->viewに、Zend_View_Interfaceに<br /><br />
沿って作成したSmartyクラスを設定すること。<br /><br />
これがあって初めて、既存の$this->render()などが利用できます。</p>
<br />
<p>なぜこの方法にいきついたかの理由は、デフォルトのテンプレートエンジンである<br /><br />
Zend_Viewを利用する際には、ほとんど利用されていないメソッドだからです。<br /><br />
Zend_Viewを利用する場合、Zend_Controller_Action_Helper_ViewRendererという<br /><br />
ヘルパークラスが利用されています。</p>
<br />
<p>Frontコントローラーで、noViewRendererが設定されるなどして、<br /><br />
自動でレンダリング（画面描画）する機能がOFFにされていない限り、<br /><br />
上記のヘルパーを介して、Zend_Viewクラスを利用しています。<br /><br />
Zend_Controller_Actionの中の以下のメソッドでは、<br /><br />
上記ヘルパー内の同名のメソッドを呼び出します。</p>
<br />
<p>　　・render<br /><br />
　　・renderScript<br /><br />
　　・getViewScript</p>
<br />
<p>initViewに関しては、Actionクラスの生成時に同時に生成される<br /><br />
上記ヘルパークラスを、リターンするという内容になっています。</p>
<br />
<p>noViewRendererがONになっているときに、これらのメソッドを自分でプログラムに記述し、<br /><br />
Zend_Viewクラスを生成して、画面描画することもできますが、Zend_Viewを使うなら、<br /><br />
自動で行ってくれる処理を、なぜ手動にするか理由が見当たりません。<br /><br />
（自動描画は、必要な時だけOFFにすることもできるのです）</p>
<br />
<p>なので、別のテンプレートエンジンを利用するときに、オーバーライドするなら、ここかなと思ったのです。<br /><br />
ヘルパーを作るっていう手段もありますが、オーバーライドした方が簡単そうだったからです。<br /><br />
そのうち、勉強をかねて、ヘルパーを作る方法を試すかもしれません。</p>
<br />
<p>Smartyを利用することで、テンプレートの拡張子もデフォルトの&#8221;.pthml&#8221;でないものを<br /><br />
使いたい方もいるでしょう。その場合は、Actionクラス内のpublic変数である $viewSuffixを<br /><br />
書き換えることで変更可能です。</p>
<br />
<p>initViewを再定義した場合、Actionクラスのinit()などで呼び出さないと、<br /><br />
renderするタイミングまでインスタンスが生成されないため、テンプレートに<br /><br />
値を設定することができませんので、お忘れなく。</p></p>

<a href="http://twitter.com/?status=RT%20%40%3A%20Zend_View%E3%81%A7Smarty%E3%82%92%E3%83%A9%E3%83%83%E3%83%97%E3%81%99%E3%82%8B%EF%BC%92%20-%20Life%20http%3A%2F%2Ftinyurl.com%2Fyzncat9" class="tweet-this" ><img src="http://life.co-hey.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="つぶやく" alt="つぶやく" /></a>]]></content:encoded>
			<wfw:commentRss>http://life.co-hey.com/2008/01/zend_viewsmarty_1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend_ViewでSmartyをラップする</title>
		<link>http://life.co-hey.com/2008/01/zend_viewsmarty/</link>
		<comments>http://life.co-hey.com/2008/01/zend_viewsmarty/#comments</comments>
		<pubDate>Thu, 17 Jan 2008 12:46:50 +0000</pubDate>
		<dc:creator>co-hey</dc:creator>
				<category><![CDATA[framework]]></category>
		<category><![CDATA[smarty]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://life.co-hey.com//wp/?p=68</guid>
		<description><![CDATA[これを知るまで、Contorollerで、Smartyクラスを生成して使っていた...]]></description>
			<content:encoded><![CDATA[<p>
<p>これを知るまで、Contorollerで、Smartyクラスを生成して使っていたけど、<br /><br />
<a href="http://framework.zend.com/manual/ja/zend.view.scripts.html" target="_blank">Zend_Viewのドキュメント</a>に記載されていた、Smartyをラップする<br /><br />
Zend_Viewクラス(ex Zend_View_Smarty)を作成して、これを利用することで、<br /><br />
Smartyの便利さはそのままに、テンプレートへの値の設定がさらに楽に！！！</p>
<br />
<p>簡単に言うと、$key っていう変数に、$valueを設定しようとした場合、<br /><br />
<span style="color:green;">$this->_smarty->assign($key, $value);</span><br /><br />
と書いていたのが、<br /><br />
<span style="color:green;">$this->_view->$key = $value;</span><br /><br />
ってかけるようになるんです。<br /><br />
assignの記述で、よくスペルミスしていた私には、重宝する機能です。</p>
<br />
<p>smartyの設定(delimiterとか）も、連想配列にして、Zend_View_Smartyクラスの<br /><br />
生成時に、第2パラメタとして渡したら有効になります。<br /><br />
テンプレートへのパスも、setScriptPathではなく、生成時に設定した方が楽です。</p>
<br />
<p>すでに、Zendで、Smartyを使っている方でも、変更量は少なくてすみますので、<br /><br />
試す価値有りと思った方は、ぜひおためしくださーい。</p>
<br />
<p>この方法を採用していると、テンプレートエンジンを変更しようとおもった際の<br /><br />
ソースの改修もラッパークラスを変更するだけですみます。<br /><br />
テンプレートは大幅な改修になることは、避けられませんが。</p>
<br />
<p>DB操作にしても、変数に代入するイメージで、設定できるっていう<br /><br />
Zendの特徴を生かしたSmartyとの連携方法だと思います。</p>
<br />
<p>これをやったら、既存のZend_Viewのように、Zend Frameworkが、<br /><br />
Zend_View_Smartyを生成して、テンプレート特定して、画面表示までを<br /><br />
やってくれないかなーという欲がでてきました。<br /><br />
Zend_Controller_Actionを継承して、initViewあたりを再定義したら、<br /><br />
できそうだけど、他にもっと楽な方法がないか探して見ます。</p>
<br />
<p>存在しない、URLが指定された場合、action名の方は任意の処理を<br /><br />
入れれる方法がわかっているのですが、controller名が存在しない場合は、<br /><br />
エラーになるだけなので、ここをどうにかしたいところです。</p>
<br />
<p>Front Controllerを継承したクラスを作るのはちょっとおっくうなので、他の方法で。</p></p>

<a href="http://twitter.com/?status=RT%20%40%3A%20Zend_View%E3%81%A7Smarty%E3%82%92%E3%83%A9%E3%83%83%E3%83%97%E3%81%99%E3%82%8B%20-%20Life%20http%3A%2F%2Ftinyurl.com%2Fyhdxkyz" class="tweet-this" ><img src="http://life.co-hey.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="つぶやく" alt="つぶやく" /></a>]]></content:encoded>
			<wfw:commentRss>http://life.co-hey.com/2008/01/zend_viewsmarty/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

