<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Cakephp2.x on php-tips.com</title>
    <link>https://php-tips.com/tags/cakephp2.x/</link>
    <description>Recent content in Cakephp2.x on php-tips.com</description>
    <generator>Hugo</generator>
    <language>ja</language>
    <lastBuildDate>Sun, 25 Dec 2016 08:00:25 +0900</lastBuildDate>
    <atom:link href="https://php-tips.com/tags/cakephp2.x/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>CakePHP の書き方</title>
      <link>https://php-tips.com/2016/12/25/how-to-write-cakephp/</link>
      <pubDate>Sun, 25 Dec 2016 08:00:25 +0900</pubDate>
      <guid>https://php-tips.com/2016/12/25/how-to-write-cakephp/</guid>
      <description>&lt;p&gt;この記事は、&lt;a href=&#34;http://qiita.com/advent-calendar/2016/cakephp3&#34;&gt;CakePHP3 Advent Calendar 2016&lt;/a&gt; 25日目の記事ではありません。&lt;/p&gt;
&lt;h2 id=&#34;まとめ&#34;&gt;まとめ&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Controller/Componentにビジネスロジックを書かない&lt;/li&gt;
&lt;li&gt;カスタムfindを活用しよう&lt;/li&gt;
&lt;li&gt;1テーブル1モデルではなく、場面によってモデルクラスを増やそう&lt;/li&gt;
&lt;li&gt;Modelless Form / Tableless Modelを活用しよう&lt;/li&gt;
&lt;li&gt;beforeSave/afterSaveは諸刃の刃&lt;/li&gt;
&lt;li&gt;Behaviorにビジネスロジック書くのもあり&lt;/li&gt;
&lt;li&gt;View層ではView Cell/View Blockを活用しよう&lt;/li&gt;
&lt;li&gt;CRUDプラグインお勧め&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;この記事を書いた動機&#34;&gt;この記事を書いた動機&lt;/h2&gt;
&lt;p&gt;CakePHPにおいてビジネスロジックに該当するものをComponentに書くという記事を見かけるたびに、それはアンチパターンじゃないのと感じている日々。&lt;br&gt;
ビジネスロジックをどこに書くべきか、共通処理をどこに書くべきかというのを、自分の考えを整理する意味でも記事として残しておきたいと思います。&lt;/p&gt;</description>
    </item>
    <item>
      <title>CakePHP 1.3.18 および 2.4.9 のリリース</title>
      <link>https://php-tips.com/2014/05/01/release-cakephp-1-3-18-and-2-4-9/</link>
      <pubDate>Thu, 01 May 2014 22:50:47 +0900</pubDate>
      <guid>https://php-tips.com/2014/05/01/release-cakephp-1-3-18-and-2-4-9/</guid>
      <description>&lt;p&gt;CakePHP 1.3系および2.4系に対して、セキュリティ修正を含むリリースがでています。&lt;/p&gt;
&lt;p&gt;SecurityComponentの改ざんチェック機構に不備があり、意図しない処理が行われる可能性があります。&lt;/p&gt;</description>
    </item>
    <item>
      <title>CakePHP 2.x メール送信内容のテストを行う</title>
      <link>https://php-tips.com/2014/04/19/cakephp-2x-email-mock-tests/</link>
      <pubDate>Sat, 19 Apr 2014 00:14:38 +0900</pubDate>
      <guid>https://php-tips.com/2014/04/19/cakephp-2x-email-mock-tests/</guid>
      <description>&lt;p&gt;テストでメールを送信せずに、CakeEmailでのレンダリング内容を取りたい場合は、&lt;/p&gt;
&lt;pre class=&#34;lang:php decode:true &#34;&gt;// モックを作成
$CakeEmail = $this-&amp;gt;getMock(&#39;CakeEmail&#39;, array(&#39;transportClass&#39;));
$CakeEmail-&amp;gt;expects($this-&amp;gt;any())-&amp;gt;method(&#39;transportClass&#39;)
    -&amp;gt;will($this-&amp;gt;returnValue(new DebugTransport()));

// CakeEmailのMockをセット
$TestTarget-&amp;gt;CakeEmail = $CakeEmail;

// ... $TestTargetを使った何らかのメール送信を含む処理

// text形式のメッセージを取得
$bodyText = $CakeEmail-&amp;gt;message(CakeEmail::MESSAGE_TEXT);
// html形式のメッセージを取得
$bodyHtml = $CakeEmail-&amp;gt;message(CakeEmail::MESSAGE_HTML);	

// ... 適宜、値チェック

&lt;/pre&gt;
&lt;p&gt;てな感じで、&lt;code&gt;CakeEmail::transportClass()&lt;/code&gt;をスタブ化して&lt;code&gt;DebugTransport&lt;/code&gt;を返すようにする。で、&lt;code&gt;CakeEmail::message()&lt;/code&gt;でbodyを取得する。&lt;/p&gt;</description>
    </item>
    <item>
      <title>CakePHPで環境に応じた設定ファイルを読み込むためのプラグイン</title>
      <link>https://php-tips.com/2014/02/12/cakephp-environment-plugin/</link>
      <pubDate>Wed, 12 Feb 2014 08:30:11 +0900</pubDate>
      <guid>https://php-tips.com/2014/02/12/cakephp-environment-plugin/</guid>
      <description>&lt;p&gt;&lt;a title=&#34;nojimage/cakephp-environment&#34; href=&#34;https://github.com/nojimage/cakephp-environment&#34;&gt;nojimage/cakephp-environment&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;環境に応じた設定を行うためのプラグインを公開しています。 環境はファイルベースで判別するので、開発環境と本番環境の切り替えをスムーズに行うことができます。&lt;/p&gt;</description>
    </item>
    <item>
      <title>CakePHP 2.xをComposerでインストールする</title>
      <link>https://php-tips.com/2014/02/08/cakephp2-composer-install/</link>
      <pubDate>Sat, 08 Feb 2014 04:07:08 +0900</pubDate>
      <guid>https://php-tips.com/2014/02/08/cakephp2-composer-install/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;http://php-tips.com/wp-content/uploads/2014/02/logo-composer-transparent.png&#34;&gt;&lt;img class=&#34;size-full wp-image-867 aligncenter&#34; alt=&#34;logo-composer-transparent&#34; src=&#34;http://php-tips.com/wp-content/uploads/2014/02/logo-composer-transparent.png&#34; width=&#34;300&#34; height=&#34;356&#34; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;CakePHP 3.xではComposerが正式にサポートされますが、2.xでもComposerを使ってCaekPHPのコアを管理することができます。&lt;/p&gt;</description>
    </item>
    <item>
      <title>CakePHP Hash::combine() でキーと値の組み合わせがずれる</title>
      <link>https://php-tips.com/2013/12/18/cakephp-hash-combine/</link>
      <pubDate>Wed, 18 Dec 2013 10:13:13 +0900</pubDate>
      <guid>https://php-tips.com/2013/12/18/cakephp-hash-combine/</guid>
      <description>&lt;p&gt;CakePHP 2.2以降で利用できる&lt;a href=&#34;http://book.cakephp.org/2.0/ja/core-utility-libraries/hash.html#Hash::combine&#34;&gt;Hashクラスのcombineメソッド&lt;/a&gt;には以下の罠があります。&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Code:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
&lt; ?php
$data = [
	[
		&#39;id&#39; =&gt; 1,
		&#39;title&#39; =&gt; &#39;first title&#39;,
		&#39;body&#39; =&gt; &#39;first content&#39;
	],
	[
		&#39;id&#39; =&gt; 3,
		&#39;title&#39; =&gt; &#39;second title&#39;,
		&#39;body&#39; =&gt; &#39;second content&#39;,
		&#39;more&#39; =&gt; &#39;second more content&#39;
	],
	[
		&#39;id&#39; =&gt; 5,
		&#39;title&#39; =&gt; &#39;third title&#39;,
		&#39;body&#39; =&gt; &#39;third content&#39;,
		&#39;more&#39; =&gt; &#39;third more content&#39;
	],
];

$results = Hash::combine($data, &#39;{n}.id&#39;, &#39;{n}.more&#39;);

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;この場合、$resultsは以下の値になることを期待するでしょう。&lt;/p&gt;</description>
    </item>
    <item>
      <title>CakePHPのCookieComponent::writeのencryptがデフォルトでは暗号になってない件</title>
      <link>https://php-tips.com/2013/12/12/cakephp-cookiecomponent/</link>
      <pubDate>Thu, 12 Dec 2013 22:48:03 +0900</pubDate>
      <guid>https://php-tips.com/2013/12/12/cakephp-cookiecomponent/</guid>
      <description>&lt;blockquote class=&#34;twitter-tweet&#34; lang=&#34;ja&#34;&gt;正しいタイトル→ CakePHPのCookieComponent::writeのencryptがデフォルトでは暗号になってない件 ですね / “PHP はいつもわたしに新鮮な驚きを与えてくれる - 猫型の蓄音機は 1 分間に 45…” &lt;a href=&#34;http://t.co/UkWZCHbtGN&#34;&gt;http://t.co/UkWZCHbtGN&lt;/a&gt;
&lt;p&gt;— Hisateru Tanaka (@tanakahisateru) &lt;a href=&#34;https://twitter.com/tanakahisateru/statuses/410794216277561344&#34;&gt;2013, 12月 11&lt;/a&gt;&lt;/blockquote&gt;
 &lt;/p&gt;</description>
    </item>
    <item>
      <title>CakeEmailのメールアドレスチェックを回避する</title>
      <link>https://php-tips.com/2013/07/12/avoid-cakeemail-email-address-validatio/</link>
      <pubDate>Fri, 12 Jul 2013 22:34:50 +0900</pubDate>
      <guid>https://php-tips.com/2013/07/12/avoid-cakeemail-email-address-validatio/</guid>
      <description>&lt;p&gt;この記事はCakePHP2以降、2.4.0までを対象とした記事です。&lt;/p&gt;
&lt;p&gt;CakePHP2からCakeEmailクラスにおいて、メールアドレスのセット時に&lt;code&gt;Validation::email()&lt;/code&gt;を用いた検証が行われるようになりました。&lt;/p&gt;</description>
    </item>
    <item>
      <title>CakePHP 2.2のHash::extract()はCentOS5/RHEL5系では使えない</title>
      <link>https://php-tips.com/2013/05/10/cakephp-2-x-hash-extract-centos5/</link>
      <pubDate>Fri, 10 May 2013 22:50:04 +0900</pubDate>
      <guid>https://php-tips.com/2013/05/10/cakephp-2-x-hash-extract-centos5/</guid>
      <description>&lt;p&gt;先日CakePHPのバグレポートをしたのでご報告。&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://cakephp.lighthouseapp.com/projects/42648/tickets/3821-hashextract-not-working-on-centos-5&#34;&gt;#3821 Hash::extract() not working on CentOS 5 - CakePHP - cakephp&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;※この話はCakePHP2.2 - 2.3.4までが該当します。次バージョン(2.3.5)以降は修正が適用されるため大丈夫です。&lt;/p&gt;</description>
    </item>
    <item>
      <title>CakePHP 2.xでJSONPに対応する</title>
      <link>https://php-tips.com/2013/01/23/how-to-return-jsonp-response-on-cakephp/</link>
      <pubDate>Wed, 23 Jan 2013 20:05:55 +0900</pubDate>
      <guid>https://php-tips.com/2013/01/23/how-to-return-jsonp-response-on-cakephp/</guid>
      <description>&lt;p&gt;CakePHP 2.xにおいて、JSONPに対応する方法を紹介します。&lt;/p&gt;
&lt;p&gt;下記に、jsonpに対応したレスポンスを返すためのコードを示します。
既にjsonでレスポンスを返せる状態となっていることが前提です。&lt;/p&gt;</description>
    </item>
    <item>
      <title>CakePHP 2.x &#43; PHPUnit on NetBeans 第2版</title>
      <link>https://php-tips.com/2012/03/19/cakephp-2x-phpunit-on-netbeans-2/</link>
      <pubDate>Mon, 19 Mar 2012 09:00:56 +0900</pubDate>
      <guid>https://php-tips.com/2012/03/19/cakephp-2x-phpunit-on-netbeans-2/</guid>
      <description>&lt;p&gt;&lt;strong style=&#34;color: red&#34;&gt;2014-06-27 注記: NetBeans 8.0以降向けに&lt;a href=&#34;http://php-tips.com/2014/06/28/cakephp-2-x-phpunit-on-netbeans-3/&#34; title=&#34;CakePHP 2.x + PHPUnit on NetBeans 第3版&#34;&gt;CakePHP 2.x + PHPUnit on NetBeans 第3版&lt;/a&gt;を書きました。&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;先日、&lt;a href=&#34;http://php-tips.com/php/2012/01/cakephp2-0-phpunit-on-netbeans&#34;&gt;CakePHPのテストをNetBeans上で実行する記事&lt;/a&gt;を書きましたが、Fixtureの作成に問題がありそのままでは実用に堪えませんでした。&lt;/p&gt;
&lt;p&gt;色々試行錯誤した結果、NetBeans側を修正することでFixtureの読み込みを行うようにするのがよい感じでしたのでその方法をご紹介します。&lt;/p&gt;
&lt;p&gt;[ad]&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
