<?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>PHP Log &#187; CakePHP</title>
	<atom:link href="http://www.php-log.de/tags/cakephp/feed" rel="self" type="application/rss+xml" />
	<link>http://www.php-log.de</link>
	<description>Eine feine Sammlung nützlicher PHP Notizen</description>
	<lastBuildDate>Mon, 20 Sep 2010 00:22:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>CakePHP &#8211; Arbeiten mit zwei Datenbanken</title>
		<link>http://www.php-log.de/505/php/cakephp-arbeiten-mit-zwei-datenbanken</link>
		<comments>http://www.php-log.de/505/php/cakephp-arbeiten-mit-zwei-datenbanken#comments</comments>
		<pubDate>Thu, 18 Mar 2010 14:00:21 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=505</guid>
		<description><![CDATA[Im Prinzip ist es sehr einfach mit zwei Datenbanken zu arbeiten. CakePHP erlaubt ja über die Member Variable $useDbConfig die Konfiguration zu ändern. Dieses Verfahren wird hier ganz schön beschrieben: http://blog.4webby.com/posts/view/6/cakephp_models_using_multiple_db_connections Aaaahber, was ist wenn es keine weitere Konfiguration gibt, weil mit einer flammneuen Datenbank gearbeitet werden soll, die man gerade eben erst selbst erzeugt [...]]]></description>
			<content:encoded><![CDATA[<p>Im Prinzip ist es sehr einfach mit zwei Datenbanken zu arbeiten. CakePHP erlaubt ja über die Member Variable $useDbConfig die Konfiguration zu ändern.</p>
<p><span id="more-505"></span></p>
<p>Dieses Verfahren wird hier ganz schön beschrieben: <a href="http://blog.4webby.com/posts/view/6/cakephp_models_using_multiple_db_connections">http://blog.4webby.com/posts/view/6/cakephp_models_using_multiple_db_connections</a></p>
<p>Aaaahber, was ist wenn es keine weitere Konfiguration gibt, weil mit einer flammneuen Datenbank gearbeitet werden soll, die man gerade eben erst selbst erzeugt hat? In diesem Fall hilft das &#8220;USE&#8221; Statement. Hier ein Bespiel:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// DB Wechseln</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;USE `other_db` ;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Query auf der neuen DB absetzen</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE configuration SET configuration_value = 'foo' WHERE configuration_key =  'bar' ;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Und wieder zurück zur alten DB</span>
<span style="color: #000088;">$current_config</span>    <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDataSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$original_db</span> 	    <span style="color: #339933;">=</span> <span style="color: #000088;">$current_config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'database'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;USE `<span style="color: #006699; font-weight: bold;">$original_db</span>` ;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/505/php/cakephp-arbeiten-mit-zwei-datenbanken/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP &#8211; Installation in einem Verzeichnis</title>
		<link>http://www.php-log.de/452/php/cakephp-installation-in-einem-verzeichnis</link>
		<comments>http://www.php-log.de/452/php/cakephp-installation-in-einem-verzeichnis#comments</comments>
		<pubDate>Wed, 02 Sep 2009 22:28:06 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[mod_rewrite]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=452</guid>
		<description><![CDATA[Üblicherweise werden CakePHP Applikation ja im Document Root eines Webserver installiert und sind dann direkt über die Domain zu erreichen. Wenn dies aber mal nicht der Fall ist, sollte man schon früh und gründlich prüfen ob der Ziel-Server überhaupt die technischen Voraussetzungen für den Betrieb einer modernen MVC Anwendung bietet. Da ich gerade vor genau [...]]]></description>
			<content:encoded><![CDATA[<p>Üblicherweise werden CakePHP Applikation ja im Document Root eines Webserver installiert und sind dann direkt über die Domain zu erreichen. Wenn dies aber mal nicht der Fall ist, sollte man schon früh und gründlich prüfen ob der Ziel-Server überhaupt die technischen Voraussetzungen für den Betrieb einer modernen MVC Anwendung bietet.<span id="more-452"></span></p>
<p>Da ich gerade vor genau diesem Problem stehe, habe ich eine kleine CakePHP Beispielanwendung zurecht geschustert, die in ein beliebiges Verzeichnis installiert werden kann. Dazu gibt es noch eine Installationsanleitung mit einigen Screenshots.</p>
<p>Download: <a href="http://www.php-log.de/wp-content/plugins/download-monitor/download.php?id=1" title="CakePHP Server Test">CakePHP Server Test</a></p>
<p>Achtung, diese Beipielanwendung ist in der index.php modifiziert. Wer Sie seine Anwendung in das regläre Directory Layout zurück transformieren will muss die index.php auf unterste Ebene anpassen oder durch das Original ersetzen.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/452/php/cakephp-installation-in-einem-verzeichnis/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP &#8211; Error: The requested address was not found on this server</title>
		<link>http://www.php-log.de/418/php/cakephp-error-the-requested-address-was-not-found-on-this-server</link>
		<comments>http://www.php-log.de/418/php/cakephp-error-the-requested-address-was-not-found-on-this-server#comments</comments>
		<pubDate>Wed, 12 Aug 2009 00:08:10 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=418</guid>
		<description><![CDATA[Sowas passiert natürlich immer wenn es gerade brennt. Man Deployed seine Anwendung, am besten wenn der Kunde dabei ist und dann spinnt ein Controller rum. Will einfach nicht gehen. Die üblichen Verdächtigen in so einem Fall sind wie hier beschrieben: Datenbankprobleme Cacheprobleme Probleme mit den Schreibrechten im /tmp Ordner In meinem Fall war es aber [...]]]></description>
			<content:encoded><![CDATA[<p>Sowas passiert natürlich immer wenn es gerade brennt. Man Deployed seine Anwendung, am besten wenn der Kunde dabei ist und dann spinnt ein Controller rum. Will einfach nicht gehen.<span id="more-418"></span></p>
<p>Die üblichen Verdächtigen in so einem Fall sind wie hier <a href="http://blog.devayd.com/2008/05/error-the-requested-address-was-not-found-on-this-server/" target="_blank">beschrieben</a>:</p>
<ul>
<li>Datenbankprobleme</li>
<li>Cacheprobleme</li>
<li>Probleme mit den Schreibrechten im /tmp Ordner</li>
</ul>
<p>In meinem Fall war es aber keiner der drei Klassiker. Ich hatte die Anwendung im Produktiv Modus und daher in der core.php den Debug-Modus aus. Configure::write(&#8216;debug&#8217;, 0);</p>
<p>Deswegen bekam ich auch keine sinnvolle Fehlermeldung, denn ich hatte einfach nur vergessen eine Modelklasse, die ohne Datenbank arbeitet, zu deployen. Deswegen lief bei mir lokal auch einwandfrei. Aber wie ich ja neulich schon erwähnte: <a href="http://www.php-log.de/404/php/554-helo-command-rejected-sorry-localhost-is-local-not-remote">Sorry, localhost is local, not remote</a> <img src='http://www.php-log.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/418/php/cakephp-error-the-requested-address-was-not-found-on-this-server/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>554 Helo command rejected: Sorry, localhost is local, not remote</title>
		<link>http://www.php-log.de/404/php/554-helo-command-rejected-sorry-localhost-is-local-not-remote</link>
		<comments>http://www.php-log.de/404/php/554-helo-command-rejected-sorry-localhost-is-local-not-remote#comments</comments>
		<pubDate>Fri, 31 Jul 2009 16:13:57 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Mail]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[SMTP]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=404</guid>
		<description><![CDATA[Vollkommen unerwartet bekomme ich nun diese Fehlermeldung beim Versenden einer E-Mail via SMTP mit der CakePHP Mail Komponente. 554 Helo command rejected: Sorry, localhost is local, not remote. Bei einer anderen Anwendung, die identischen Code verwendet und ebenfalls auf meinen lokalen Rechner läuft klappt der E-Mail-Versand. WTF&#8230; Weder Google noch Bing finden etwas relevantes für [...]]]></description>
			<content:encoded><![CDATA[<p>Vollkommen unerwartet bekomme ich nun diese Fehlermeldung beim Versenden einer E-Mail via SMTP mit der CakePHP Mail Komponente. 554 Helo command rejected: Sorry, localhost is local, not remote. Bei einer anderen Anwendung, die identischen Code verwendet und ebenfalls auf meinen lokalen Rechner läuft klappt der E-Mail-Versand. WTF&#8230;<span id="more-404"></span></p>
<p>Weder Google noch Bing finden etwas relevantes für diese Fehlermeldung. Ich habe noch ein leise Erinnerung an die Probleme die, je nach Provider, mit dem <a title="SMTP Problem" href="http://www.php-log.de/343/php/smpt-450-sender-address-rejected-domain-not-found" target="_blank">SMTP Versand</a> auftreten können. Glücklicherweise stoplterte ich aber im Cake Handbuch über die <a href="http://book.cakephp.org/de/view/481/Sending-A-Message-Using-SMTP" target="_blank">Dokumentation zur Mail Komponente </a>und die weisen Jungs bei CakePHP haben eine Lösung. Es ist der Sendeparameter &#8216;client&#8217;, den ich zuvor nie benötigte und der laut Doku nur bei nicht RFC 821 konformen SMTP Servern benötigt wird. Sobald ich für &#8216;client&#8217; den Host des SMTP Server (oder irgendeinen anderen) eingetragen habe funktioniert der Mailversand.</p>
<p>Warum es vom gleichen Host mit den gleichen SMTP Daten einmal funktioniert und ein anderes mal nicht will sich mir aber trotzdem nicht erschliessen. Naja, es mir aber auch niemals jemand versprochen, dass man als PHP Programmierer ausschliesslich auf einer Blümchenwiese lebt <img src='http://www.php-log.de/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Achso, hier auch noch das entsprechende Codesample:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> prepareSmtpSending<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">smtpOptions</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	    <span style="color: #0000ff;">'port'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">25</span><span style="color: #339933;">,</span> 
	    <span style="color: #0000ff;">'timeout'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span>
	    <span style="color: #0000ff;">'host'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'mail.irgendwo.de'</span><span style="color: #339933;">,</span>
	    <span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'hans'</span><span style="color: #339933;">,</span>
	    <span style="color: #0000ff;">'password'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'wurst'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'client'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'irgendwo.de'</span> <span style="color: #666666; font-style: italic;">// &lt;-- Die Rettung</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;">Email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">delivery</span> 	<span style="color: #339933;">=</span> <span style="color: #0000ff;">'smtp'</span><span style="color: #339933;">;</span>		
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/404/php/554-helo-command-rejected-sorry-localhost-is-local-not-remote/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP &#8211; Pagination in Verbindung mit Containable</title>
		<link>http://www.php-log.de/392/allgemeines/cakephp-pagination-in-verbindung-mit-containable</link>
		<comments>http://www.php-log.de/392/allgemeines/cakephp-pagination-in-verbindung-mit-containable#comments</comments>
		<pubDate>Wed, 29 Jul 2009 19:00:36 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[Allgemeines]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Containable]]></category>
		<category><![CDATA[Pagination]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=392</guid>
		<description><![CDATA[Das Behaviour Containable ist eines der Highlights bei der Arbeit mit CakePHP, erlaubt doch es quasi wahlfreien Zugriff auf verknüpfte Datensätze. Häufig benötigt man die Dienste von Containable in Kombination mit einer Pagination. Das ist im Handbuch auch ganz gut dokumentiert. Ich möchte hier aber auf eine Besonderheit in der Notation aufmerksam machen, und zwar [...]]]></description>
			<content:encoded><![CDATA[<p>Das Behaviour Containable ist eines der Highlights bei der Arbeit mit CakePHP, erlaubt doch es quasi wahlfreien Zugriff auf verknüpfte Datensätze. <span id="more-392"></span></p>
<p>Häufig benötigt man die Dienste von Containable in Kombination mit einer Pagination. Das ist im Handbuch auch ganz gut <a href="http://book.cakephp.org/de/view/474/Containable">dokumentiert</a>. Ich möchte hier aber auf eine Besonderheit in der Notation aufmerksam machen, und zwar die Verknüpfung mittels Punktnotation. Folgendes Codefragment aus der Praxis soll dass verdeutlichen.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> revenues<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$conditions</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Revenue.user_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user_id</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Revenue.status'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'pending'</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;">paginate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'conditions'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$conditions</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'contain'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Client.User'</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// &lt;-- Hier liegt die Magie</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$revenues</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paginate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Revenue'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Durch die &#8216;contain&#8217; Zeile erhalten wir ein Array von folgender Struktur:</p>
<pre>
Array
(
    [0] => Array
        (
            [Revenue] => Array
                (
                    [id] => 10
                    [status] => pending
                     ...
                    [updated] => 2009-07-29 20:19:27
                    [created] => 2009-07-29 20:19:27
                )
            [Client] => Array
                (
                    [id] => 17
                    [user_id] => 15
                     ...
// Der verknüpfte Datensatz wird von Containable eingesetzt
                    [User] => Array
                        (
                            [id] => 15
                            [name] => Hans
                            ...
                        )
                )
        )
)
</pre>
<p>Ohne die contain Zeile bekämen wir dieses Array, es fehlt der User:</p>
<pre>
Array
(
    [0] => Array
        (
            [Revenue] => Array
                (
                    [id] => 10
                    [status] => pending
                     ...
                    [updated] => 2009-07-29 20:19:27
                    [created] => 2009-07-29 20:19:27
                )
            [Client] => Array
                (
                    [id] => 17
                    [user_id] => 15
                )
        )
)
</pre>
<p><strong>Update</strong><br />
Wichtig: Wer mit Containable arbeitet sollte unbedingt darauf achten das Feld &#8216;recursion&#8217; aus seinem $conditions Array zu löschen. Andernfalls gibt es Probleme mit tiefen Rekursionen im Kontext von Containable</p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/392/allgemeines/cakephp-pagination-in-verbindung-mit-containable/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP &#8211; Pagination bei einer HABTM Beziehung</title>
		<link>http://www.php-log.de/383/php/cakephp-pagination-bei-einer-habtm-beziehung</link>
		<comments>http://www.php-log.de/383/php/cakephp-pagination-bei-einer-habtm-beziehung#comments</comments>
		<pubDate>Tue, 21 Jul 2009 02:04:50 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[HABTM]]></category>
		<category><![CDATA[Pagination]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=383</guid>
		<description><![CDATA[Das Handbuch ist nicht allzu Gesprächig was dieses Thema angeht. Glücklicherweise gibt es eine funktionierende, aber nicht gut dokumentierte Lösung. Zu finden ist sie beim Cakebaker. Es gibt einen Key für die Pagination, für den ich keine Doku finden konnte. Falls jemand in der offiziellen Doku etwas finden sollte, freue ich mich über jeden Hinweis [...]]]></description>
			<content:encoded><![CDATA[<p>Das Handbuch ist nicht allzu Gesprächig was dieses Thema angeht. Glücklicherweise gibt es eine funktionierende, aber nicht gut dokumentierte Lösung.<span id="more-383"></span></p>
<p>Zu finden ist sie beim <a target="_blank" href="http://cakebaker.42dh.com/2007/10/17/pagination-of-data-from-a-habtm-relationship/">Cakebaker</a>. Es gibt einen Key für die Pagination, für den ich keine Doku finden konnte. Falls jemand in der offiziellen Doku etwas finden sollte, freue ich mich über jeden Hinweis und Kommentar.<br />
Der Key lautet <code>joins</code> und erwartet ein Array das die Beziehung definiert.</p>
<p>In meinem Fall ist es so, dass Produkte und User in einer HABTM Beziehung stehen. Die Auflösungstabelle ist products_users und hat die übliche HABTM Struktur.  Hier der Code, der für mich in der Index Funktion meines Controllers funktioniert.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paginate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'Product'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'limit'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'joins'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
		        <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
		            <span style="color: #0000ff;">'table'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'products_users'</span><span style="color: #339933;">,</span> 
		            <span style="color: #0000ff;">'alias'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ProductUser'</span><span style="color: #339933;">,</span> 
		            <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'inner'</span><span style="color: #339933;">,</span>  
		            <span style="color: #0000ff;">'conditions'</span><span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ProductUser.product_id = Product.id'</span><span style="color: #009900;">&#41;</span> 
		        <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
		        <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
		            <span style="color: #0000ff;">'table'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'users'</span><span style="color: #339933;">,</span> 
		            <span style="color: #0000ff;">'alias'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'User'</span><span style="color: #339933;">,</span> 
		            <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'inner'</span><span style="color: #339933;">,</span>  
		            <span style="color: #0000ff;">'conditions'</span><span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
		                <span style="color: #0000ff;">'User.id = ProductUser.user_id'</span><span style="color: #339933;">,</span> 
		                <span style="color: #0000ff;">'User.id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user_id</span>
		            <span style="color: #009900;">&#41;</span> 
		        <span style="color: #009900;">&#41;</span>
		        <span style="color: #009900;">&#41;</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;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'products'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paginate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Product'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Das ganze ist natürlich einiges an Code, es gibt auch eine <a href="http://bakery.cakephp.org/articles/view/quick-tip-doing-ad-hoc-joins-in-model-find">Lösung</a> die das meiste in den app_controller packt, die ich nicht benutze, aber der Vollständigkeit erwähnen wollte. Sollte jemand eine bessere Lösung kennen bitte ich um Erleuchtung <img src='http://www.php-log.de/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/383/php/cakephp-pagination-bei-einer-habtm-beziehung/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP &#8211; Einfluss auf die Paginator URL nehmen</title>
		<link>http://www.php-log.de/372/php/cakephp-einfluss-auf-die-paginator-url-nehmen</link>
		<comments>http://www.php-log.de/372/php/cakephp-einfluss-auf-die-paginator-url-nehmen#comments</comments>
		<pubDate>Wed, 17 Jun 2009 09:54:35 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Pagination]]></category>
		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=372</guid>
		<description><![CDATA[In den Views mit Hilfe der Methoden prev(), next() und numbers() zwischen den einzelnen Seiten einer Auflistung navigiert werden. Was aber ist zu tun wenn man die URL anpassen möchte? Soll z.B. an eine URL wie diese /users/index/page:2 noch eine ID angehängt werden, so dass man diese URL erhält /users/index/23/page:2 kann man das folgendermaßen erreichen [...]]]></description>
			<content:encoded><![CDATA[<p>In den Views mit Hilfe der Methoden prev(), next() und numbers() zwischen den einzelnen Seiten einer Auflistung navigiert werden. Was aber ist zu tun wenn man die URL anpassen möchte?<span id="more-372"></span></p>
<p>Soll z.B. an eine URL wie diese /users/index/page:2 noch eine ID angehängt werden, so dass man diese URL erhält /users/index/23/page:2 kann man das folgendermaßen erreichen</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$paginator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prev</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;&lt; '</span><span style="color: #339933;">.</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'zurück'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">23</span><span style="color: #009900;">&#41;</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: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'class'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'disabled'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$paginator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">numbers</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">23</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$paginator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">next</span><span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'weiter'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' &gt;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">23</span><span style="color: #009900;">&#41;</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: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'class'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'disabled'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/372/php/cakephp-einfluss-auf-die-paginator-url-nehmen/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP &#8211; Die undokumentierte sort() Methode im paginator</title>
		<link>http://www.php-log.de/337/php/cakephp/cakephp-die-undokumentierte-sort-methode-im-paginator</link>
		<comments>http://www.php-log.de/337/php/cakephp/cakephp-die-undokumentierte-sort-methode-im-paginator#comments</comments>
		<pubDate>Fri, 29 May 2009 09:49:13 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Pagination]]></category>
		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=337</guid>
		<description><![CDATA[Das Thema Pagination ist in CakePHP sehr gut gelöst, es gibt eigentlich nichts was ich bisher vermissen würde. Allein mit der Dokumentation liegen die Entwickler ein wenig hinten. Gerade was die Methode &#8220;sort&#8221; die vom Scafolder so eingesetzt wird $paginator-&#62;sort(&#8216;field&#8217;); angeht, herrscht doch ein wenig Erklärungsnotstand. Hier also mal  alle mir bisher bekannten Optionen im [...]]]></description>
			<content:encoded><![CDATA[<p>Das Thema Pagination ist in CakePHP sehr gut gelöst, es gibt eigentlich nichts was ich bisher vermissen würde. Allein mit der Dokumentation liegen die Entwickler ein wenig hinten. <span id="more-337"></span>Gerade was die Methode &#8220;sort&#8221; die vom Scafolder so eingesetzt wird $paginator-&gt;sort(&#8216;field&#8217;); angeht, herrscht doch ein wenig Erklärungsnotstand. Hier also mal  alle mir bisher bekannten Optionen im Überblick:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$paginator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sort</span><span style="color: #009900;">&#40;</span>
    <span style="color: #666666; font-style: italic;">// Der Text des Links. Nicht den zweiten Parameter (1) vergessen, sonst gibt es keinen Link</span>
    __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Ansprechpartner'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>    
&nbsp;
    <span style="color: #666666; font-style: italic;">// Das Datenbankfeld nach dem sortiert wird</span>
     <span style="color: #0000ff;">'spokesman'</span><span style="color: #339933;">,</span> 
&nbsp;
    <span style="color: #666666; font-style: italic;">// Zusätzliche Optionen, dies scheint ein cake-übliches $options Array zu sein</span>
    <span style="color: #666666; font-style: italic;">// Zumindest der Key 'url' für das Anpassen einer URL funktioniert</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Obiges Beispiel erzeugt folgenden Link: /addresses/index/user_id:12</p>
<p>Hier noch mal das ganze ohne Kommentare zum pasten:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$paginator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sort</span><span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Ansprechpartner'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'spokesman'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'User'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/337/php/cakephp/cakephp-die-undokumentierte-sort-methode-im-paginator/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP &#8211; Ein Model in einem anderen nutzen</title>
		<link>http://www.php-log.de/331/php/cakephp/cakephp-ein-model-in-einem-anderen-nutzen</link>
		<comments>http://www.php-log.de/331/php/cakephp/cakephp-ein-model-in-einem-anderen-nutzen#comments</comments>
		<pubDate>Wed, 20 May 2009 10:33:02 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=331</guid>
		<description><![CDATA[Das Handbuch schweigt sich darüber aus, vielleicht weil man es als Verstoß gegen das MVC Paradigma ansehen könnte? Ich weiß es nicht. Die Lösung ist wie immer recht einfach. Ein Classloader&#8230;&#8230;sehr praktisch und wie es scheint an allen Stellen einsetzbar: http://api.cakephp.org/class/class-registry Und so sieht es dann ein einem Model aus: class Model extends AppModel &#123; [...]]]></description>
			<content:encoded><![CDATA[<p>Das Handbuch schweigt sich darüber aus, vielleicht weil man es als Verstoß gegen das MVC Paradigma ansehen könnte? Ich weiß es nicht. Die Lösung ist wie immer recht einfach. Ein Classloader&#8230;<span id="more-331"></span>&#8230;sehr praktisch und wie es scheint an allen Stellen einsetzbar:</p>
<p><a href="http://api.cakephp.org/class/class-registry">http://api.cakephp.org/class/class-registry</a></p>
<p>Und so sieht es dann ein einem Model aus:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Model <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> doIt<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">OtherModel</span> <span style="color: #339933;">=</span> ClassRegistry<span style="color: #339933;">::</span><span style="color: #004000;">init</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;OtherModel&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$other</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">OtherModel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findById</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Die Verantwortung für das Laden eines Models in ein anderes liegt damit beim Programmier. Das große Vorbild Ruby On Rails stellt dem Entwickler alle Modelle an allen Stellen direkt zur Verfügung, PHP ist nicht Ruby. Ich werde deswegen lieber eine Modelbezogene Methode entwickeln.</p>
<p>Selbstredend lässt so auch jedes Model in einen View Helper laden! Wollte das nur mal erwähnen wegen den Suma&#8217;s</p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/331/php/cakephp/cakephp-ein-model-in-einem-anderen-nutzen/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP &#8211; SaveField mit MySQL Funktionen wie z.B. Now()</title>
		<link>http://www.php-log.de/328/mysql/cakephp-savefield-mit-mysql-funktionen-wie-zb-now</link>
		<comments>http://www.php-log.de/328/mysql/cakephp-savefield-mit-mysql-funktionen-wie-zb-now#comments</comments>
		<pubDate>Fri, 15 May 2009 10:09:44 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Controller]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=328</guid>
		<description><![CDATA[Dummerweise erlaubt es CakePHP nicht beim aktualisieren eines einzelnen Datenbankfeldes auf MySQL aufzurufen. Eine kurze Rechereche braucht auch keine wirkliche Abhilfe. Das einzige was ich gefunden habe ist ein Hinweis darauf dass schon mal jemand diese Funktion vermisst hat, auch eine Patch möglich ist, dieser aber nicht in die das offizielle Release aufgenommen wird.Einzelheiten dazu [...]]]></description>
			<content:encoded><![CDATA[<p>Dummerweise erlaubt es CakePHP nicht beim aktualisieren eines einzelnen Datenbankfeldes auf MySQL aufzurufen. Eine kurze Rechereche braucht auch keine wirkliche Abhilfe. Das einzige was ich gefunden habe ist ein Hinweis darauf dass schon mal jemand diese Funktion vermisst hat, auch eine Patch möglich ist, dieser aber nicht in die das offizielle Release aufgenommen wird.<span id="more-328"></span>Einzelheiten dazu findet man im Cake <a href="https://trac.cakephp.org/ticket/3341" target="_blank">Ticketsystem</a></p>
<p>Ich mich dazu entschieden meine Datenbank Klasse nicht zu patchen, es reicht ja schon dass ich für eine saubere Ausgabe von Monatsnamen im Core rumstochern muss. Auf eine weitere Ausnahme und Fehlerquelle habe ich keine Lust mehr. Statdessen habe ich mir lieber eine simple Funktion in den Application Controller gelegt.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Im Application Controller</span>
<span style="color: #009933; font-style: italic;">/**
 * creates a date value, suitable for mysql datetime fields
 *
 * @return string
 * @author Ralf Kramer
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> now<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">strftime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%Y-%m-%d %H:%M:%S'</span><span style="color: #339933;">,</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</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: #666666; font-style: italic;">// Im Controller dann:</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">saveField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a_datetime_field'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">now</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></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/328/mysql/cakephp-savefield-mit-mysql-funktionen-wie-zb-now/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

