<?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; Controller</title>
	<atom:link href="http://www.php-log.de/tags/controller/feed" rel="self" type="application/rss+xml" />
	<link>http://www.php-log.de</link>
	<description>Eine feine Sammlung nützlicher PHP Notizen</description>
	<lastBuildDate>Thu, 27 May 2010 04:43:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<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>
		<item>
		<title>Ein paar Fakten über den Pages Controller</title>
		<link>http://www.php-log.de/179/php/nutzung-des-pages-controller</link>
		<comments>http://www.php-log.de/179/php/nutzung-des-pages-controller#comments</comments>
		<pubDate>Mon, 16 Feb 2009 13:56:27 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Controller]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=179</guid>
		<description><![CDATA[Templates die in /views/pages/ abgelegt werden sind ohne weiteres zutun unter http://www.domain.com/pages erreichbar. Beispiel: /views/pages/impressum.ctp wird angezeigt wenn http://www.domain.com/pages/impressum aufgerufen wird. Nach einer Standardinstallation von CakePHP existiert er nicht im /app/controllers Folder. Wenn eine Route auf einen Pages View eingerichtet werden soll geht das so: Router::connect&#40;'/impressum.html', array&#40;'controller' =&#62; 'pages', 'action' =&#62; 'display', 'tandc'&#41;&#41;; Die Action [...]]]></description>
			<content:encoded><![CDATA[<p>Templates die in /views/pages/ abgelegt werden sind ohne weiteres zutun unter http://www.domain.com/pages erreichbar. Beispiel: /views/pages/impressum.ctp wird angezeigt wenn http://www.domain.com/pages/impressum aufgerufen wird.<span id="more-179"></span></p>
<p>Nach einer Standardinstallation von CakePHP existiert er nicht im /app/controllers Folder.</p>
<p>Wenn eine Route auf einen Pages View eingerichtet werden soll geht das so:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Router<span style="color: #339933;">::</span><span style="color: #004000;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/impressum.html'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'controller'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'pages'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'display'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'tandc'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Die Action ist &#8220;display&#8221;, und die ID ist der Name des Templates.</p>
<p>Der eigentliche Pages Controller wohnt in &#8220;/cake/libs/controllers&#8221;.</p>
<p>Wenn zum Pages Controller weitere Funktionalität hinzugefügt werden soll ist es ratsam diesen nach /app/controllers/ zu kopieren. Dann geht bei einem Update der Cake Library keine Funktionalität verloren.</p>
<p><a href="http://bakery.cakephp.org/articles/view/taking-advantage-of-the-pages-controller" target="_blank">Weitere Infos über den Pages Controller</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/179/php/nutzung-des-pages-controller/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fortgeschrittene Anwendung der Tree Komponente</title>
		<link>http://www.php-log.de/141/php/fortgeschrittene-anwendung-der-tree-komponente</link>
		<comments>http://www.php-log.de/141/php/fortgeschrittene-anwendung-der-tree-komponente#comments</comments>
		<pubDate>Wed, 04 Feb 2009 15:41:38 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Controller]]></category>
		<category><![CDATA[Tree]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=141</guid>
		<description><![CDATA[Das Tree Behaviour von CakePHP nutzt die Modified Preorder Tree Traversal (MPTT) Technik. Im Gegensatz zur hierarchischen Speichermethode für Bäume, werden hierbei Teilmengen gebildet und durch die Parameter &#8220;left&#8221; und &#8220;right&#8221; eingegrenzt. Dieser Artikel enthält eine Grafik die dass Prinzip sehr schön verdeutlicht. Um an eine Teilmenge in Form eines Astes oder &#8220;Nodes&#8221; zu gelangen, [...]]]></description>
			<content:encoded><![CDATA[<p>Das Tree Behaviour von CakePHP nutzt die Modified Preorder Tree Traversal (MPTT) Technik. Im Gegensatz zur hierarchischen Speichermethode für Bäume, werden hierbei Teilmengen gebildet und durch die Parameter &#8220;left&#8221; und &#8220;right&#8221; eingegrenzt. Dieser <a href="http://dev.mysql.com/tech-resources/articles/hierarchical-data.html" target="_blank">Artikel</a> enthält eine Grafik die dass Prinzip sehr schön verdeutlicht. Um an eine Teilmenge in Form eines Astes oder &#8220;Nodes&#8221; zu gelangen, werden einfach die Parameter &#8216;left&#8217; und &#8216;right&#8217; genutzt. <span id="more-141"></span></p>
<p>Mit den eingebauten Methoden des Behaviours Tree stößt man relativ schnell an Grenzen, deswegen ist das Wissen um die einfache Handhabung der Daten sehr wichtig. Um zum Beispiel an alle Kind Elemente eines Baumes zu gelangen bietet Tree die Methode children() an. Was aber wenn nur die Children geholt werden sollen deren Name mit A beginnt, oder dem status active oder die Daten sollen in eine Pagination geschossen werden? Ganz klar, die Daten müssen mit der find() Methode des Models geholt werden. Hier ein wenig Sample Code für eine Tree Pagination:</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: #000000; font-weight: bold;">class</span> UsersController <span style="color: #000000; font-weight: bold;">extends</span> AppController <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Users'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> search<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Wir holen den gewünschten Eintrag aus der DB</span>
		<span style="color: #666666; font-style: italic;">// anhand des Primärschlüssels</span>
		<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">User</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findById</span><span style="color: #009900;">&#40;</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;">// Wir nutzen dessen left und right Werte um ´</span>
		<span style="color: #666666; font-style: italic;">// den Ast einzugrenzen</span>
		<span style="color: #000088;">$search_options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'User.lft &gt; '</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lft'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'User.rght &lt; '</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'rght'</span><span style="color: #009900;">&#93;</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Fügen hier noch die besondere Suchbedingung ein</span>
		<span style="color: #000088;">$search_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'User.lastname LIKE '</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;a%&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Und übergeben den Rest dem Pagination Helper</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;">'users'</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;">'User'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$search_options</span><span style="color: #009900;">&#41;</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>So einfach ist das&#8230;im Prinzip&#8230;</p>
<p>Ein weiterer guter Artikel der sich mit dem Thema beschäftigt findet sich <a href="http://www.sitepoint.com/print/hierarchical-data-database/">hier</a>. Es gibt auch eine sehr einfache Formel um die Anzahl der Kinder eines Knotens zu ermitteln, dazu ist kein SQL notwendig und deswegen hervorragend für die Verwendung innerhalb von Views geeignet.</p>
<blockquote><p>Anzahl Nodes = (right &#8211; left &#8211; 1) / 2</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/141/php/fortgeschrittene-anwendung-der-tree-komponente/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP und der beforeFilter()</title>
		<link>http://www.php-log.de/97/php/cakephp-und-der-beforefilter</link>
		<comments>http://www.php-log.de/97/php/cakephp-und-der-beforefilter#comments</comments>
		<pubDate>Mon, 02 Feb 2009 00:19:36 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Controller]]></category>
		<category><![CDATA[Filter]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=97</guid>
		<description><![CDATA[Mann muss sich beim Einsatz der beforeFilter in den Controllern bewusst sein, dass diese Methode nur einmal ausgeführt wird. Für weitere Aufrufe in übergeordneten Controllern ist man selbst verantwortlich. Wer also einen AppController im Einsatz hat und dort einen beforeFilter für allgemeine Aufgaben definiert, läuft Gefahr diese Funktionalität zu verlieren wenn im Child-Controller auch ein [...]]]></description>
			<content:encoded><![CDATA[<p>Mann muss sich beim Einsatz der beforeFilter in den Controllern bewusst sein, dass diese Methode nur einmal ausgeführt wird. Für weitere Aufrufe in übergeordneten Controllern ist man selbst verantwortlich. Wer also einen AppController im Einsatz hat und dort einen beforeFilter für allgemeine Aufgaben definiert, läuft Gefahr diese Funktionalität zu verlieren wenn im Child-Controller auch ein beforeFilter definiert wird. Abhilfe schafft dann der Aufruf des parent Filters. Man muss halt nur dran denken&#8230;</p>
<p><span id="more-97"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> AppController <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">function</span> beforeFilter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
              <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Dank an den UserController der seine Eltern nicht vergisst. Guter Junge...&quot;</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> UsersController <span style="color: #000000; font-weight: bold;">extends</span> AppController <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">function</span> beforeFilter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		parent<span style="color: #339933;">::</span><span style="color: #004000;">beforeFilter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #666666; font-style: italic;">// anderer Code...</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/97/php/cakephp-und-der-beforefilter/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
