<?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>古の技術 &#8211; エンジニア見習い</title>
	<atom:link href="https://otonan-syusyoku.work/archives/tag/%e5%8f%a4%e3%81%ae%e6%8a%80%e8%a1%93/feed" rel="self" type="application/rss+xml" />
	<link>https://otonan-syusyoku.work</link>
	<description>三流プログラマー</description>
	<lastBuildDate>Sun, 05 May 2024 13:37:40 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://otonan-syusyoku.work/wp-content/uploads/2023/10/cropped-名称未設定のデザイン-16-32x32.png</url>
	<title>古の技術 &#8211; エンジニア見習い</title>
	<link>https://otonan-syusyoku.work</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>CakePHPのmatchingで困った話</title>
		<link>https://otonan-syusyoku.work/archives/1729</link>
					<comments>https://otonan-syusyoku.work/archives/1729#respond</comments>
		
		<dc:creator><![CDATA[hrokig2]]></dc:creator>
		<pubDate>Sat, 20 Apr 2024 11:49:20 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[古の技術]]></category>
		<guid isPermaLink="false">https://otonan-syusyoku.work/?p=1729</guid>

					<description><![CDATA[古の技術と呼ばれることも多くなってきたCakePHPの記事です。 CakePHPを使った開発の際に躓いたポイントを解説しますぅ 概要 データ取得時に関連データを合わせて取得したい。関連データの取得時には条件に一致しないデ [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>古の技術と呼ばれることも多くなってきたCakePHPの記事です。</p>
<p>CakePHPを使った開発の際に躓いたポイントを解説しますぅ</p>
<h2>概要</h2>
<p>データ取得時に関連データを合わせて取得したい。関連データの取得時には条件に一致しないデータが</p>
<p>関連データを用いて取得条件を絞りこみ、関連データが条件に一致しない場合、親も取得しないようにしたい。</p>
<h2>関連データの取得方法</h2>
<p><span>CakePHPでのデータ取得は<code>matching</code>, <code>innerJoinWith</code> を用いることで、SQLのJOINに類似した操作が実現できます。</span></p>
<p><span>これにより、特定の関連データに基づく厳密なデータフィルタリングが可能となります。</span></p>
<p>matchingはN:Nの関係性のときに強力な関数となるが、条件指定の際に思った挙動にならないため注意が必要。</p>
<h2>MatchingとInnerJoinWith</h2>
<p>対応表として以下の形になる。</p>
<table style="border-collapse: collapse; width: 100%;">
<tbody>
<tr>
<td style="width: 33.4449%;"></td>
<td style="width: 33.2217%;">matching</td>
<td style="width: 33.3333%;">innerJoinWith</td>
</tr>
<tr>
<td style="width: 33.4449%;">関連データの取得</td>
<td style="width: 33.2217%;">できる</td>
<td style="width: 33.3333%;">できない</td>
</tr>
<tr>
<td style="width: 33.4449%;">関連データの条件指定</td>
<td style="width: 33.2217%;">できる</td>
<td style="width: 33.3333%;">できる</td>
</tr>
<tr>
<td style="width: 33.4449%;">条件一致しない場合の挙動</td>
<td style="width: 33.2217%;">空として</td>
<td style="width: 33.3333%;"></td>
</tr>
<tr>
<td style="width: 33.4449%;">生成されるSQL</td>
<td style="width: 33.2217%;"><span>Inner Join</span></td>
<td style="width: 33.3333%;"><span>Inner Join</span></td>
</tr>
<tr>
<td style="width: 33.4449%;">使用どころ</td>
<td style="width: 33.2217%;">N:Nの関係のときにとりあえず便利</td>
<td style="width: 33.3333%;"><span>関連データに基いて結果を計算したいとき使う<br />
(サブクエリとして取ったり…</span></td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://otonan-syusyoku.work/archives/1729/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>CakePHPのURL生成で死んだ話</title>
		<link>https://otonan-syusyoku.work/archives/1731</link>
					<comments>https://otonan-syusyoku.work/archives/1731#respond</comments>
		
		<dc:creator><![CDATA[hrokig2]]></dc:creator>
		<pubDate>Sat, 20 Apr 2024 10:07:10 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[生涯独学]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[古の技術]]></category>
		<guid isPermaLink="false">https://otonan-syusyoku.work/?p=1731</guid>

					<description><![CDATA[古の技術と呼ばれることも多くなってきたCakePHPの記事です。 CakePHPのマニュアルのせいで時間取られたので、備忘録として残しておきっます。 概要 Commandクラスからメールに添付するURL生成を行いたい。  [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>古の技術と呼ばれることも多くなってきたCakePHPの記事です。</p>
<p>CakePHPのマニュアルのせいで時間取られたので、備忘録として残しておきっます。</p>
<h2>概要</h2>
<p>Commandクラスからメールに添付するURL生成を行いたい。</p>
<p>その際に生成されるURLはHTTPS化されたURLを添付したい。</p>
<p>&nbsp;</p>
<p>現環境 ↓</p>
<ul>
<li>CakePHP 4.4</li>
<li>PHP 8.1</li>
</ul>
<h2>困ったこと</h2>
<p><span class="sc_marker blue"><strong>ControllerやViewでURL生成を行うと現在のoriginを見るのですが、Commandクラスなどoriginを見れないものは明示的にオプションを示さないといけないのがCakePHPの掟です。</strong></span></p>
<p>今回の目的である、CommandクラスからHTTPS化されたURLを添付するにはどうしたらいいかというと、マニュアルのとおりに、生成時のオプションにHTTPSの指定をする必要がある。</p>
<blockquote><p>_https true にすると普通の URL から https に変換します。 false にすると、強制的に http になります。</p>
<p><cite class="blockquote_ref"> <a href="https://book.cakephp.org/4/ja/development/routing.html#id25" target="_blank" rel="noopener noreferrer">URL の生成</a> </cite></p></blockquote>
<pre class="line-numbers"><code class="language-php">$routes-&gt;url([
    'controller' =&gt; 'コントローラー名',
    'action' =&gt; 'アクション名',
    '_https' =&gt; true,
]);</code></pre>
<p>&nbsp;</p>
<p>これだけでHTTPSを指定できるのは、便利だなと思った矢先、HTTPSになっていない。</p>
<p>Routerクラスのインポート、スペルミスなどを確認してもHTTPS化ができていない。</p>
<p>&nbsp;</p>
<p>どうしてもHTTPS化が必須の要件だった、CakePHP3のマニュアルも読んでみた。</p>
<p><strong>驚きの展開だったのが、Cake3とCake４でオプションの内容が違うことがわかった。</strong></p>
<blockquote><p>_ssl true にすると普通の URL から https に変換します。 false にすると、強制的に http になります。</p>
<p><cite class="blockquote_ref"> <a href="https://book.cakephp.org/3/ja/development/routing.html#id23" target="_blank" rel="noopener noreferrer">URL の生成</a> </cite></p></blockquote>
<p>&nbsp;</p>
<p>以下の形で指定すると今回の目的を達成することができた。</p>
<pre class="line-numbers"><code class="language-php">$routes-&gt;url([
    'controller' =&gt; 'Articles',
    'action' =&gt; 'index',
    '_ssl' =&gt; true,
]);</code></pre>
<p>&nbsp;</p>
<p>枯れた技術を使うのはちょっと手間がかかりますねぇ。</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://otonan-syusyoku.work/archives/1731/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
