<?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>Dabits &#187; CakePHP</title>
	<atom:link href="http://www.dabits.net/archives/category/tips/cakephp/feed" rel="self" type="application/rss+xml" />
	<link>http://www.dabits.net</link>
	<description>-環境構築屋-</description>
	<lastBuildDate>Mon, 05 Dec 2011 20:08:31 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>cakephp1.2流のエレメントキャッシュ</title>
		<link>http://www.dabits.net/archives/12</link>
		<comments>http://www.dabits.net/archives/12#comments</comments>
		<pubDate>Sat, 02 May 2009 11:33:22 +0000</pubDate>
		<dc:creator>dabits</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://tips.dabits.net/?p=11</guid>
		<description><![CDATA[サイドメニューなど、エレメントの部分だけキャッシュしたかったので、 マニュアルの3.9.3.2 エレメントをキャッシュするを見て、実装したのですが、 コントローラ側からCache::read();としても反応なし。 ・・ &#8230; <a href="http://www.dabits.net/archives/12">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>サイドメニューなど、エレメントの部分だけキャッシュしたかったので、<br />
マニュアルの<a href="http://book.cakephp.org/ja/view/561/Caching-Elements">3.9.3.2 エレメントをキャッシュする</a>を見て、実装したのですが、<br />
コントローラ側からCache::read();としても反応なし。<br />
・・・？と思いながらview.phpを眺めていると、以下の記述が。。。</p>

<div class="igBar"><span id="lphp-5"><a href="#" onclick="javascript:showPlainTxt('php-5'); return false;"><span class="caps">PLAIN TEXT</span></a></span></div><div class="syntax_hilite"><span class="langName"><span class="caps">PHP</span>:</span><br /><div id="php-5">
<div class="php"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$expires</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$cacheFile</span> = <span style="color:#FF0000;">&#8216;element_&#8217;</span> . <span style="color:#0000FF;">$key</span> . <span style="color:#FF0000;">&#8216;_&#8217;</span> . <span style="color:#0000FF;">$plugin</span> . Inflector::<span style="color:#006600;">slug</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$name</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$cache</span> = cache<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">&#8216;views&#8217;</span> . DS . <span style="color:#0000FF;">$cacheFile</span>, <span style="color:#000000; font-weight:bold;">null</span>, <span style="color:#0000FF;">$expires</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/is_string"><span style="color:#000066;">is_string</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$cache</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#0000FF;">$cache</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div></li></ol></div>
</div></div><br />

<p>あれ、cache();って1.1のやつだから非推奨のはずじゃぁ。。。<br />
ってことで、cakephp1.2流のelementキャッシュを考えてみた。</p>

●view側<br />
<div class="igBar"><span id="lphp-6"><a href="#" onclick="javascript:showPlainTxt('php-6'); return false;"><span class="caps">PLAIN TEXT</span></a></span></div><div class="syntax_hilite"><span class="langName"><span class="caps">PHP</span>:</span><br /><div id="php-6">
<div class="php"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$this</span>-&gt;;element<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">&#8216;left_menu&#8217;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span>; </div></li></ol></div>
</div></div><br />
の代わりに以下を挿入<br />
<div class="igBar"><span id="lphp-7"><a href="#" onclick="javascript:showPlainTxt('php-7'); return false;"><span class="caps">PLAIN TEXT</span></a></span></div><div class="syntax_hilite"><span class="langName"><span class="caps">PHP</span>:</span><br /><div id="php-7">
<div class="php"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$element</span> = Cache::<span style="color:#006600;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">&#8216;left_menu&#8217;</span>, <span style="color:#FF0000;">&#8216;element&#8217;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> === <span style="color:#000000; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$element</span> = <span style="color:#0000FF;">$this</span>-&gt;element<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">&#8216;left_menu&#8217;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; Cache::<span style="color:#006600;">write</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">&#8216;left_menu&#8217;</span>, <span style="color:#0000FF;">$element</span>, <span style="color:#FF0000;">&#8216;element&#8217;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$element</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div></li></ol></div>
</div></div><br />

●コントローラ側<br />
beforeFilterなどでエレメントキャッシュを定義し、<br />
キャッシュが存在しない場合に限り、クエリを発行する。<br />
<div class="igBar"><span id="lphp-8"><a href="#" onclick="javascript:showPlainTxt('php-8'); return false;"><span class="caps">PLAIN TEXT</span></a></span></div><div class="syntax_hilite"><span class="langName"><span class="caps">PHP</span>:</span><br /><div id="php-8">
<div class="php"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$config</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF0000;">&#8216;engine&#8217;</span> =&gt; <span style="color:#FF0000;">&#8216;File&#8217;</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF0000;">&#8216;duration&#8217;</span>=&gt; <span style="color:#FF0000;">&#8216;+5 min&#8217;</span>,</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF0000;">&#8216;path&#8217;</span> =&gt; <span class="caps">CACHE</span> . <span style="color:#FF0000;">&#8216;views&#8217;</span> . <span class="caps">DS,</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF0000;">&#8216;prefix&#8217;</span> =&gt; <span style="color:#FF0000;">&#8216;element_&#8217;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Cache::<span style="color:#006600;">config</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">&#8216;element&#8217;</span>, <span style="color:#0000FF;">$config</span><span style="color:#006600; font-weight:bold;">&#41;</span>;&lt;/code&gt;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span> Cache::<span style="color:#006600;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">&#8216;left_menu&#8217;</span>, <span style="color:#FF0000;">&#8216;element&#8217;</span><span style="color:#006600; font-weight:bold;">&#41;</span> === <span style="color:#000000; font-weight:bold;">false</span> <span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$areas</span> = <span style="color:#0000FF;">$this</span><del>&gt;Area</del>&gt;find<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">&#8216;menu&#8217;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$categories</span> = <span style="color:#0000FF;">$this</span><del>&gt;Category</del>&gt;find<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">&#8216;menu&#8217;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;set<span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/compact"><span style="color:#000066;">compact</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">&#8216;areas&#8217;</span>, <span style="color:#FF0000;">&#8216;categories&#8217;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div></li></ol></div>
</div></div><br />

<p>これで劇早&amp;1.2流のキャッシュができましたー！</p>]]></content:encoded>
			<wfw:commentRss>http://www.dabits.net/archives/12/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>データベースが文字化けしたら&#8230;</title>
		<link>http://www.dabits.net/archives/10</link>
		<comments>http://www.dabits.net/archives/10#comments</comments>
		<pubDate>Sun, 26 Oct 2008 11:45:22 +0000</pubDate>
		<dc:creator>dabits</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://tips.dabits.net/archives/9</guid>
		<description><![CDATA[CakePHPで開発している際に、phpmyadminなどでデータベースの中身を表示させようとすると、 文字化けする事があります。 これは、CakePHP内のdatabase.phpに記述が足りない事が原因の模様。。。  &#8230; <a href="http://www.dabits.net/archives/10">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[CakePHPで開発している際に、phpmyadminなどでデータベースの中身を表示させようとすると、<br />
文字化けする事があります。<br />
これは、CakePHP内のdatabase.phpに記述が足りない事が原因の模様。。。<br />
<div class="igBar"><span id="lphp-10"><a href="#" onclick="javascript:showPlainTxt('php-10'); return false;"><span class="caps">PLAIN TEXT</span></a></span></div><div class="syntax_hilite"><span class="langName"><span class="caps">PHP</span>:</span><br /><div id="php-10">
<div class="php"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">var</span> <span style="color:#0000FF;">$default</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span>&nbsp; &nbsp;<span style="color:#FF0000;">&#8216;driver&#8217;</span> =&gt; <span style="color:#FF0000;">&#8216;mysql&#8217;</span>,</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF0000;">&#8216;connect&#8217;</span> =&gt; <span style="color:#FF0000;">&#8216;mysql_connect&#8217;</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF0000;">&#8216;host&#8217;</span> =&gt; <span style="color:#FF0000;">&#8216;localhost&#8217;</span>,</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF0000;">&#8216;login&#8217;</span> =&gt; <span style="color:#FF0000;">&#8216;root&#8217;</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF0000;">&#8216;password&#8217;</span> =&gt; <span style="color:#FF0000;">&#8221;</span>,</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF0000;">&#8216;database&#8217;</span> =&gt; <span style="color:#FF0000;">&#8216;encodetest&#8217;</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF0000;">&#8216;encoding&#8217;</span> =&gt; <span style="color:#FF0000;">&#8216;utf8&#8242;</span>, ←この部分を追加</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF0000;">&#8216;prefix&#8217;</span> =&gt; <span style="color:#FF0000;">&#8221;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div></li></ol></div>
</div></div><br />
(前のデータは化けてしまいますが、)これで新規データ分については文字化けが起こらないようになりました。<br />
参考:<a href="http://php.sunvisor.net/2007/11/cakephp_2.html" target="_blank">続・CakePHPと文字化け (PHP学習日記)</a>]]></content:encoded>
			<wfw:commentRss>http://www.dabits.net/archives/10/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
