<?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>Ralfs Zend Framework und PHP Blog &#187; Tutorial</title>
	<atom:link href="http://www.ralfeggert.de/kategorie/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ralfeggert.de</link>
	<description>Bloggen über das Zend Framework, PHP und anderes Gedöns</description>
	<lastBuildDate>Tue, 29 Sep 2009 07:15:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Aktuell: Zend Framework Tutorial pausiert</title>
		<link>http://www.ralfeggert.de/2007/03/31/aktuell-zend-framework-tutorial-pausiert/</link>
		<comments>http://www.ralfeggert.de/2007/03/31/aktuell-zend-framework-tutorial-pausiert/#comments</comments>
		<pubDate>Sat, 31 Mar 2007 07:56:53 +0000</pubDate>
		<dc:creator>Ralf Eggert</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.ralfeggert.de/2007/03/31/aktuell-zend-framework-tutorial-pausiert/</guid>
		<description><![CDATA[Derzeit bin ich sehr stark mit Arbeit eingedeckt und kann mich momentan leider nicht um die Aktualisierung des Zend Framework Tutorials kümmern. Unsere Firma Travello GmbH ist derzeit dabei, unsere Reiseportale komplett neu zu überarbeiten. Natürlich auf Basis des Zend Frameworks. Diese Arbeit geht zur Zeit vor und ein Ende ist momentan noch nicht abzusehen.
In [...]]]></description>
			<content:encoded><![CDATA[<p>Derzeit bin ich sehr stark mit Arbeit eingedeckt und kann mich momentan leider nicht um die Aktualisierung des <a href="http://www.ralfeggert.de/zend-framework-tutorial/">Zend Framework Tutorials</a> kümmern. Unsere Firma <a href="http://www.travello.de/">Travello GmbH</a> ist derzeit dabei, unsere Reiseportale komplett neu zu überarbeiten. Natürlich auf Basis des Zend Frameworks. Diese Arbeit geht zur Zeit vor und ein Ende ist momentan noch nicht abzusehen.</p>
<p>In letzter Zeit habe ich für das Tutorial viele Supportanfragen und E-Mails von PHP Entwicklern bekommen. Ich schaffe es aber einfach nicht, alle Anfragen zu bearbeiten. Deshalb gibt es Bestrebungen, dass komplette Tutorial <a href="http://www.ralfeggert.de/2007/01/04/zend-framework-tutorial-an-die-community-uebergeben/">an die Community zu übergeben</a>, so dass die Zend Framework Community das Tutorial und das darin erstellte Blog gemeinsam weiter pflegen und voran bringen kann. Dies ist leider auch ein wenig eingeschlafen, was zum großen Teil auch an meinem Zeitmangel liegt. Die Anfänge des <a href="http://zftut.warui.info/">Zend Framework Tutorial Brutkastens</a> sind schon zu begutachten, aber noch nicht weit fortgeschritten. Wer Lust hat, das Tutorial umzuziehen und auf den neuesten Stand zu bringen, der kann sich gerne bei mir melden.</p>
<p>Ich hoffe, dass ich in Zukunft wieder ein wenige mehr zum Bloggen kommen, wenn auch nicht für das Tutorial, dann aber doch eher allgemeiner Natur. Schauen wir mal.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ralfeggert.de/2007/03/31/aktuell-zend-framework-tutorial-pausiert/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Zend Framework Tutorial an die Community übergeben?</title>
		<link>http://www.ralfeggert.de/2007/01/04/zend-framework-tutorial-an-die-community-uebergeben/</link>
		<comments>http://www.ralfeggert.de/2007/01/04/zend-framework-tutorial-an-die-community-uebergeben/#comments</comments>
		<pubDate>Thu, 04 Jan 2007 10:18:10 +0000</pubDate>
		<dc:creator>Ralf Eggert</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.ralfeggert.de/2007/01/04/zend-framework-tutorial-an-die-community-uebergeben/</guid>
		<description><![CDATA[Nach gründlicher Überlegung habe ich den Entschluss gefasst, mein Zend Framework Tutorial an die Community zu übergeben. Das soll bedeuten, dass ich das Tutorial nicht mehr alleine pflege, sondern die deutsche Zend Framework Community dabei hilft, ein verständliches und tiefgehendes Tutorial für alle Einsteiger zu schaffen.
Die Gründe für diese Entscheidung sind vielfältig. Allen voran habe [...]]]></description>
			<content:encoded><![CDATA[<p>Nach gründlicher Überlegung habe ich den Entschluss gefasst, mein <a href="http://www.ralfeggert.de/zend-framework-tutorial/">Zend Framework Tutorial</a> an die Community zu übergeben. Das soll bedeuten, dass ich das Tutorial nicht mehr alleine pflege, sondern die deutsche Zend Framework Community dabei hilft, ein verständliches und tiefgehendes Tutorial für alle Einsteiger zu schaffen.</p>
<p>Die Gründe für diese Entscheidung sind vielfältig. Allen voran habe ich mit der Zeit gemerkt, dass die Pflege des Tutorials beim Erscheinen neuer Releases einfach zu lange dauert, wenn ich mich darum alleine kümmere. Außerdem hat sich gezeigt, dass ein Blog für solch ein Tutorial doch nicht unbedingt die geeignetste Form darstellt. Zumal auch die Druckversion schon immer zu wünschen übrig lässt. Ich bin mittlerweile der Meinung, dass ein Wiki besser für das umfangreiche Tutorial geeignet ist. Zudem hoffe ich, mit der sich gerade entwickelnden Community beim deutschen <a href="http://www.zfforum.de/" target="_blank">Zend Framework Forum</a> einige begeisterte Helfer für die Fortführung des Tutorials zu finden.</p>
<p>Im Grunde werden zwei Dinge benötigt. Zum einen ein Wiki für die Pflege der Tutorial Seiten und zum anderen ein SVN Server für die Verwaltung der Projektdateien, mit dem auch der Code für die einzelnen Kapitel des Tutorials verwaltet werden können, damit jeder sich bei Bedarf den vollständigen Code jedes Kapitels downloaden kann. Die Zend Framework Website bietet mit dem <a href="http://framework.zend.com/svn/laboratory/" target="_blank">Laboratory</a> und dem <a href="http://framework.zend.com/wiki/dashboard.action" target="_blank">Wiki</a> bereits die technischen Voraussetzungen, um das Tutorial von der Community pflegen und fortführen zu können. Es wäre aber auch denkbar, ein eigenes Wiki aufzusetzen. Ein eigener SVN Server wiederum würde meiner Meinung nach weniger Sinn machen.</p>
<p>Ich möchte nun alle Interessierten zur Diskussion einladen, </p>
<ul>
<li>wie man das Ganze gemeinsam umsetzen könnte</li>
<li>ob man die vorhandenen technischen Voraussetzungen nutzt</li>
<li>ob man eigenen technische Voraussetzungen schafft (halte ich persönlich eher für ungünstig)</li>
<li>wer Interesse hat, sich an der Umsetzung zu beteiligen</li>
<li>wer ggf. an einer Übersetzung in andere Sprachen (vor allem Englisch) interessiert ist</li>
<li>was sonst noch so einfällt</li>
</ul>
<p>Dazu bitte entweder in den Kommentaren hier im Blog melden oder die Diskussion im Zend Framework Forum nutzen. Ich freue mich auf zahlreiche Meinung.</p>
<ul>
<li><a href="http://www.zfforum.de/showthread.php?t=68" target="_blank">Zur Diskussion im Zend Framework Forum</a></li>
</ul>
<p>Natürlich werde ich auch weiterhin am Tutorial mitarbeiten und werde sicher auch neue Teile beisteuern. Aber gerade die Pflege nach einem neuen Release artet sehr schnell in Fleißarbeit aus, wenn z.B. eine Änderung in allen Codepaketen eingepflegt werden muss. Parallel werde ich mich auch mit dem Server Team in Verbindung setzen, wie man das Tutorial und die Codebasis auf der Zend Framework Website integrieren könnte.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ralfeggert.de/2007/01/04/zend-framework-tutorial-an-die-community-uebergeben/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Zend Framework Tutorial verzögert sich</title>
		<link>http://www.ralfeggert.de/2006/11/22/zend-framework-tutorial-verzoegert-sich/</link>
		<comments>http://www.ralfeggert.de/2006/11/22/zend-framework-tutorial-verzoegert-sich/#comments</comments>
		<pubDate>Wed, 22 Nov 2006 08:28:14 +0000</pubDate>
		<dc:creator>Ralf Eggert</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.ralfeggert.de/2006/11/22/zend-framework-tutorial-verzoegert-sich/</guid>
		<description><![CDATA[Einige haben es sicher schon bemerkt: das Zend Framework Tutorial verzögert sich derzeit ein wenig. Die beiden Hauptgründe sind die knappe Zeit und die Änderungen an den MVC Komponenten, die derzeit noch nicht in der Library, sondern nur im Incubator verfügbar sind. Da ich wahrscheinlich alle Tutorial Teile überarbeiten muss, wenn das neue Release mit [...]]]></description>
			<content:encoded><![CDATA[<p>Einige haben es sicher schon bemerkt: das <a href="http://www.ralfeggert.de/2006/08/26/einfuehrung-und-anforderungen/">Zend Framework Tutorial</a> verzögert sich derzeit ein wenig. Die beiden Hauptgründe sind die knappe Zeit und die Änderungen an den MVC Komponenten, die derzeit noch nicht in der Library, sondern nur im Incubator verfügbar sind. Da ich wahrscheinlich alle Tutorial Teile überarbeiten muss, wenn das neue Release mit den MVC Änderungen erschienen ist, halte ich die neuen Teile noch so lange zurück und bitte noch um ein wenig Geduld.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ralfeggert.de/2006/11/22/zend-framework-tutorial-verzoegert-sich/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Zend Framework Tutorial Sonderausgabe: Update auf Release 0.2.0</title>
		<link>http://www.ralfeggert.de/2006/11/09/zend-framework-tutorial-release-02/</link>
		<comments>http://www.ralfeggert.de/2006/11/09/zend-framework-tutorial-release-02/#comments</comments>
		<pubDate>Thu, 09 Nov 2006 09:59:14 +0000</pubDate>
		<dc:creator>Ralf Eggert</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.ralfeggert.de/2006/11/09/zend-framework-tutorial-release-02/</guid>
		<description><![CDATA[Oops, habe ganz vergessen, diesen Beitrag freizuschalten.
In dieser Sonderausgabe des Zend Framework Tutorials werden wir das TravelloBlog auf das vor wenigen Tagen veröffentliche Release 0.2.0 anpassen. Der ursprünglich geplante zwölfte Teil für das Versenden und Empfangen von Trackbacks wird deshalb um eine Woche verschoben. Das Anpassen der bestehenden Tutorialteile ist durchaus zeitintensiv.
Mit dem Release 0.2.0 [...]]]></description>
			<content:encoded><![CDATA[<p><em>Oops, habe ganz vergessen, diesen Beitrag freizuschalten.</em></p>
<p>In dieser Sonderausgabe des <strong>Zend Framework Tutorials</strong> werden wir das TravelloBlog auf das <a href="http://www.ralfeggert.de/2006/10/31/zend-framework-release-02-erschienen/">vor wenigen Tagen veröffentliche Release 0.2.0</a> anpassen. Der ursprünglich geplante zwölfte Teil für das Versenden und Empfangen von Trackbacks wird deshalb um eine Woche verschoben. Das Anpassen der bestehenden Tutorialteile ist durchaus zeitintensiv.</p>
<p>Mit dem Release 0.2.0 gab es einige Neuerungen, auch wenn noch nicht alles direkt in der Library des Zend Frameworks aufgenommen worden ist. Die meisten Änderungen sind erst im <a href="http://www.ralfeggert.de/2006/09/05/was-ist-eigentlich-der-zend-framework-incubator/">Incubator</a> vorhanden, so dass ich in dieser Sonderausgabe nur auf die Änderungen an der eigentlichen Library eingehen werde. </p>
<p><strong>Wichtig</strong>: Dieses Tutorial setzt die Zend Framework Preview Version 0.2.0 voraus und kann bei der Verwendung einer aktuelleren Version aus dem SVN unter Umständen nicht zu 100% funktionieren. Des weiteren setzt diese Sonderausgabe voraus, dass du das Tutorial bis einschließlich <a href="http://www.ralfeggert.de/2006/10/30/zend-framework-tutorial-zend_log-zend_mail/">zum elften Teil</a> durchgearbeitet hast. </p>
<p><span id="more-74"></span></p>
<ul>
<li><a href="#release_0.2">Auf Release 0.2 updaten</a></li>
<li><a href="#zend_config">Zend_Config</a></li>
<li><a href="#zend_controller_rewriterouter">Zend_Controller_RewriteRouter</a></li>
<li><a href="#zend_config_2">Noch einmal Zend_Config</a></li>
<li><a href="#weitere_fehler">Weitere Fehler</a></li>
<li><a href="#download">Download</a></li>
<li><a href="#zusammenfassung">Zusammenfassung</a></li>
<li><a href="#comments">Kommentare</a></li>
</ul>
<h3><a name="release_0.2">Auf Release 0.2.0 updaten</a></h3>
<p>Als erstes musst du dir das aktuelle Release 0.2.0 von der <a href="http://framework.zend.com/download/stable">Zend Framework Download Seite</a> herunterladen und es in ein Verzeichnis außerhalb des TravelloBlog Projektes entpacken. Im Verzeichnis "/library/zf" löscht du das Unterverzeichnis "/Zend" und die Datei "Zend.php". Du kannst die Dateien aber auch überschreiben. </p>
<p>In deinem Zend Framework Verzeichnis außerhalb des TravelloBlog Projektes suchst du nun das Unterverzeichnis "/library" und kopierst das Unterverzeichnis "/Zend" und die Datei "Zend.php" in das Verzeichnis "/library/zf". Damit ist das Update schon abgeschlossen.</p>
<h3><a name="zend_config">Zend_Config</a></h3>
<p>Als nächstes starte bitte das TravelloBlog in deinem Browser unter der Adresse "http://travelloblog/". Sofort wird dir eine Fehlermeldung angezeigt: </p>
<div class="textbox">
Call to undefined method Zend_Config_Ini::load() in e:\travelloblog\application\config\settings.php on line 53
</div>
<p>Wir sehen sofort, in welcher Datei und in welcher Zeile dieser Datei wir nach dem Fehler suchen müssen. Öffne also die Datei "settings.php" im Verzeichnis "/application/config" und navigiere zu Zeile 53.</p>
<p>Das Erstellen eines Zend_Config_Ini Objektes hat sich mit dem neuen Release deutlich vereinfacht. Statt </p>
<div class="igBar"><span id="lphp-9"><a href="#" onclick="javascript:showCodeTxt('php-9'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-9">
<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> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Config<span style="color:#006600; font-weight:bold;">&#40;</span>Zend_Config_Ini::<span style="color:#006600;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$iniFile</span>, <span style="color:#0000FF;">$section</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>kannst du nun einfach</p>
<div class="igBar"><span id="lphp-10"><a href="#" onclick="javascript:showCodeTxt('php-10'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<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:#0000FF;">$config</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Config_Ini<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$iniFile</span>, <span style="color:#0000FF;">$section</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>schreiben. Schon wurde der Fehler von eben korrigiert. Wenn du dein TravelloBlog im Browser neu aufrufst, taucht aber gleich der nächste Fehler auf.</p>
<h3><a name="zend_controller_rewriterouter">Zend_Controller_RewriteRouter</a></h3>
<p>Die nächste Fehlermeldung betrifft den Zend_Controller_RewriteRouter und ist ein wenig umfangreicher als die erste:</p>
<div class="textbox">
Argument 2 passed to Zend_Controller_RewriteRouter::addRoute() must be an object of class Zend_Controller_Router_Route_Interface, called in e:\travelloblog\application\config\settings.php on line 71 and defined in e:\travelloblog\library\zf\Zend\Controller\RewriteRouter.php on line 64
</div>
<p>Wir erkennen, dass der Fehler wieder in unserer "settings.php" Datei liegt. Dieses Mal jedoch in Zeile 71. Mit dem Release 0.2.0 erwartet Zend_Controller_RewriteRouter nun die Übergabe eines Zend_Controller_Router_Route Objektes statt der reinen Parameterliste wie bisher. </p>
<p>Ändere also die Zeilen</p>
<div class="igBar"><span id="lphp-11"><a href="#" onclick="javascript:showCodeTxt('php-11'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-11">
<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;">$router</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Controller_RewriteRouter<span style="color:#006600; font-weight:bold;">&#40;</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;"><span style="color:#0000FF;">$router</span>-&gt;<span style="color:#006600;">addRoute</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'actionroute'</span>, <span style="color:#FF0000;">':controller/:action/:id'</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'controller'</span> =&gt; <span style="color:#FF0000;">'article'</span>, <span style="color:#FF0000;">'action'</span> =&gt; <span style="color:#FF0000;">'index'</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:#0000FF;">$router</span>-&gt;<span style="color:#006600;">addRoute</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'404route'</span>, <span style="color:#FF0000;">'filenotfound/'</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'controller'</span> =&gt; <span style="color:#FF0000;">'index'</span>, <span style="color:#FF0000;">'action'</span> =&gt; <span style="color:#FF0000;">'filenotfound'</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;">Zend::<span style="color:#006600;">register</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'router'</span>, <span style="color:#0000FF;">$router</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>wie folgt ab:</p>
<div class="igBar"><span id="lphp-12"><a href="#" onclick="javascript:showCodeTxt('php-12'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-12">
<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;">$route1</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Controller_Router_Route<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">':controller/:action/:id'</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'controller'</span> =&gt; <span style="color:#FF0000;">'article'</span>, <span style="color:#FF0000;">'action'</span> =&gt; <span style="color:#FF0000;">'index'</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;"><span style="color:#0000FF;">$route2</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Controller_Router_Route<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'filenotfound/'</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'controller'</span> =&gt; <span style="color:#FF0000;">'index'</span>, <span style="color:#FF0000;">'action'</span> =&gt; <span style="color:#FF0000;">'filenotfound'</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$router</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Controller_RewriteRouter<span style="color:#006600; font-weight:bold;">&#40;</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:#0000FF;">$router</span>-&gt;<span style="color:#006600;">addRoute</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'actionroute'</span>, <span style="color:#0000FF;">$route1</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;"><span style="color:#0000FF;">$router</span>-&gt;<span style="color:#006600;">addRoute</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'404route'</span>, <span style="color:#0000FF;">$route2</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;">Zend::<span style="color:#006600;">register</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'router'</span>, <span style="color:#0000FF;">$router</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Du kannst die Zend_Controller_Router_Route natürlich auch direkt bei der Übergabe an die  addRoute() Methode instantiieren, dann werden die beiden Zeilen nur etwa unübersichtlicher. </p>
<p>Ein Reload des TravelloBlogs in deinem Browser birgt aber gleich den nächsten Fehler. Und zwar steigt der Firefox mit einer Umleitungsschleife aus während der Internet Explorer behauptet, dass die Seite nicht angezeigt werden kann.</p>
<p>Dieses Problem lösen wir, indem wir für den RewriteRouter noch die Rewrite Basis setzen:</p>
<div class="igBar"><span id="lphp-13"><a href="#" onclick="javascript:showCodeTxt('php-13'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-13">
<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;">$router</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Controller_RewriteRouter<span style="color:#006600; font-weight:bold;">&#40;</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;"><span style="color:#0000FF;">$router</span>-&gt;<span style="color:#006600;">addRoute</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'actionroute'</span>, <span style="color:#0000FF;">$route1</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:#0000FF;">$router</span>-&gt;<span style="color:#006600;">addRoute</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'404route'</span>, <span style="color:#0000FF;">$route2</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;"><span style="color:#0000FF;">$router</span>-&gt;<span style="color:#006600;">setRewriteBase</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">''</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;">Zend::<span style="color:#006600;">register</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'router'</span>, <span style="color:#0000FF;">$router</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Zum Abschluss der Änderungen für den Zend_Controller_RewriteRouter können wir den Bugfix in unserer Funktion getRewriteBase() in unserer "settings.php" Datei nun wieder herausnehmen:</p>
<div class="igBar"><span id="lphp-14"><a href="#" onclick="javascript:showCodeTxt('php-14'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-14">
<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;">function</span> getRewriteBase<span style="color:#006600; font-weight:bold;">&#40;</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;"><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;">$url</span> = Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'router'</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">getRewriteBase</span><span style="color:#006600; font-weight:bold;">&#40;</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; </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:#616100;">return</span> <span style="color:#0000FF;">$url</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;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Das war es schon mit den Änderungen für den  Zend_Config_RewriteRouter. Wenn du nun das TravelloBlog wieder in deinem Browser aufrufst, sollte wieder alles funktionieren. </p>
<p>Wenn du das TravelloBlog in einem Unterverzeichnis betreibst, musst du das Setzen der Rewrite Basis entsprechend anpassen:</p>
<div class="igBar"><span id="lphp-15"><a href="#" onclick="javascript:showCodeTxt('php-15'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-15">
<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;">$router</span>-&gt;<span style="color:#006600;">setRewriteBase</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'/travelloblog/public'</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h3><a name="zend_config_2">Noch einmal Zend_Config</a></h3>
<p>Das nächste Problem ist ein wenig schwieriger zu finden. Lasse dir einmal einen beliebigen Artikel anzeigen und erstelle dann einen neuen Kommentar. Du erhältst mehrere Meldungen, u.a.</p>
<div class="textbox">
Notice: Trying to get property of non-object in e:\travelloblog\application\controllers\CommentController.php on line 41</p>
<p>Notice: Trying to get property of non-object in e:\travelloblog\application\controllers\CommentController.php on line 42
</p></div>
<p>Wenn du den CommentController öffnest, findest du dort folgende Zeilen:</p>
<div class="igBar"><span id="lphp-16"><a href="#" onclick="javascript:showCodeTxt('php-16'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-16">
<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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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:#0000FF;">$mail</span>-&gt;<span style="color:#006600;">setFrom</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">mail</span>-&gt;<span style="color:#006600;">defaultsender</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; &nbsp; &nbsp; <span style="color:#0000FF;">$mail</span>-&gt;<span style="color:#006600;">addTo</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">mail</span>-&gt;<span style="color:#006600;">defaultrecipient</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; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<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>
<p></p>
<p>Es muss sich also auch wieder um ein Problem mit Zend_Config handeln. Wenn du dir die "settings.ini" Datei im Verzeichnis "/application/config" anschaust, siehst du, dass wir die Angaben für den Default Sender und Empfänger nur im Abschnitt "[production]" aber nicht im Abschnitt "[development]" definiert haben. Die Vererbung mit Hilfe des "extends = production" funktioniert ab Release 0.2.0 also nicht mehr. </p>
<p>Für Abhilfe ist aber schnell gesorgt. Ändere in der "settings.ini" die Zeilen</p>
<div class="codebox">
<pre>
[development]
extends = production
</pre>
</div>
<p>einfach in</p>
<div class="codebox">
<pre>
[development : production]
</pre>
</div>
<p>um und versuche erneut einen Kommentar zu erstellen. Die Fehlermeldungen sollten alle verschwunden sein. </p>
<h3><a name="weitere_fehler">Weitere Fehler</a></h3>
<p>Weitere Fehler durch das Upgrade auf Release 0.2.0 konnte ich bisher nicht finden. Wenn du weitere Fehler gefunden hast, melde dich bitte in den Kommentaren, dann kann ich diesen Artikel bei Bedarf ergänzen.</p>
<h3><a name="download">Download</a></h3>
<p>Der aktuelle Stand des Tutorials nach dieser Sonderausgabe kann herunter geladen werden. Die Textdateien "empty.txt" in einigen Verzeichnissen habe ich nur angelegt, weil mein Winzip keine leeren Verzeichnisse im Zip Archiv anlegt:</p>
<ul>
<li><a href="http://www.ralfeggert.de/zfw/version-0.11a.zip">http://www.ralfeggert.de/zfw/version-0.11a.zip</a></li>
</ul>
<p>Die Zip Datei enthält nicht die aktuelle Version des Zend Frameworks. Dies musst du bitte selber in das entsprechende Verzeichnis kopieren. </p>
<h3><a name="zusammenfassung">Zusammenfassung</a></h3>
<p>In dieser Sonderausgabe des Zend Framework Tutorials haben wir unser TravelloBlog für das neue Release 0.2.0 angepasst und sämtliche durch das Upgrade aufgetretenen Fehler beseitigt.</p>
<p>Nach dieser Sonderausgabe kommen wir im nächsten Teil des Zend Framework Tutorials dann zu dem sehr spannenden Thema für das Versenden und Empfangen von Trackbacks mit Hilfe von Zend_Http_Client.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ralfeggert.de/2006/11/09/zend-framework-tutorial-release-02/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Zend Framework Tutorial Teil 11: Nützliche Komponenten Zend_Log und Zend_Mail</title>
		<link>http://www.ralfeggert.de/2006/10/30/zend-framework-tutorial-zend_log-zend_mail/</link>
		<comments>http://www.ralfeggert.de/2006/10/30/zend-framework-tutorial-zend_log-zend_mail/#comments</comments>
		<pubDate>Mon, 30 Oct 2006 08:03:59 +0000</pubDate>
		<dc:creator>Ralf Eggert</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.ralfeggert.de/2006/10/30/zend-framework-tutorial-zend_log-zend_mail/</guid>
		<description><![CDATA[Im zehnten Teil vom Zend Framework Tutorial haben wir die Zend_Cache Komponente für das Cachen von Templates und Datenbankabfragen kennen gelernt und in unser Projekt integriert. Wenn du die ersten zehn Teile noch nicht gelesen hast, hole dies bitte schnell nach.
In diesem elften Teil des Zend Framework Tutorials werde ich gleich zwei Komponenten vorstellen. Mit [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ralfeggert.de/2006/10/24/zend-framework-tutorial-zend_cache/">Im zehnten Teil</a> vom Zend Framework Tutorial haben wir die Zend_Cache Komponente für das Cachen von Templates und Datenbankabfragen kennen gelernt und in unser Projekt integriert. Wenn du die ersten zehn Teile noch nicht gelesen hast, <a href="http://www.ralfeggert.de/2006/08/26/einfuehrung-und-anforderungen/#aufbau">hole dies bitte schnell nach</a>.</p>
<p>In diesem elften Teil des Zend Framework Tutorials werde ich gleich zwei Komponenten vorstellen. Mit Hilfe von Zend_Mail kannst du auf einfache Weise E-Mails erstellen und versenden und die Komponente Zend_Log ist für das individuelle Erstellen von Logs zuständig. </p>
<p>Wenn du über neue <strong>Tutorial</strong> Teile informiert werden möchtest, abonniere am besten den <a href="http://www.ralfeggert.de/feed/">Feed</a> dieses Blogs. Dann verpasst du garantiert keinen Teil des Tutorials.</p>
<p>Wichtig: Dieses Tutorial setzt die Zend Framework Preview Version 0.2.0 voraus und kann bei der Verwendung einer aktuelleren Version aus dem SVN unter Umständen nicht zu 100% funktionieren. </p>
<p><span id="more-71"></span></p>
<h3>Inhaltsverzeichnis</h3>
<ul>
<li><a href="#zend_mail">Zend_Mail</a></li>
<li><a href="#wichtig">Wichtiger Hinweis</a></li>
<li><a href="#vorueberlegungen1">Vorüberlegungen für Zend_Mail</a></li>
<li><a href="#commentcontroller">CommentController anpassen</a></li>
<li><a href="#uebung1">Übung 1: Zend_Mail für neue Artikel</a></li>
<li><a href="#zend_log">Zend_Log</a></li>
<li><a href="#vorueberlegungen2">Vorüberlegung für Zend_Log</a></li>
<li><a href="#datenbankaenderungen">Datenbankänderungen loggen</a></li>
<li><a href="#uebung2">Übung 2: Zend_Log für Kommentare, Tags und Kategorien</a></li>
<li><a href="#download">Download</a></li>
<li><a href="#zusammenfassung">Zusammenfassung</a></li>
<li><a href="#changelog">Change log</a></li>
<li><a href="#navigation">Navigation</a></li>
<li><a href="#comments">Kommentare</a></li>
</ul>
<h3><a name="zend_mail">Zend_Mail</a></h3>
<p>Für den ersten Einblick in die Zend_Mail Komponente empfehle ich wie immer natürlich den Blick in das <a href="http://framework.zend.com/manual/de/zend.mail.html">Zend_Mail Kapitel</a> im Zend Framework Manual. Dort erfährst du neben der Funktionsweise des einfachen Versands und dem Versand per SMTP auch alles Wissenswerte über HTML E-Mail, Mailanhänge, das Setzen von zusätzlichen Headern und weiteren Empfängern sowie MIME-Abgrenzung und Zeichensätzen.</p>
<div class="textbox">
Hinweis</p>
<p>Bisher ist die Zend_Mail Komponente nur für den Versand von E-Mails zuständig. An einer Erweiterung auch für den Empfang von E-Mails wird aber bereits gearbeitet.
</p></div>
<p>Die grundlegende Funktionsweise ist recht simpel und leicht zu durchschauen. Hier ein erstes Beispiel (entnommen aus dem Manual):</p>
<div class="igBar"><span id="lphp-28"><a href="#" onclick="javascript:showCodeTxt('php-28'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-28">
<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;">require_once</span> <span style="color:#FF0000;">'Zend/Mail.php'</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:#0000FF;">$mail</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Mail<span style="color:#006600; font-weight:bold;">&#40;</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;"><span style="color:#0000FF;">$mail</span>-&gt;<span style="color:#006600;">setBodyText</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Dies ist der Text dieser E-Mail.'</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:#0000FF;">$mail</span>-&gt;<span style="color:#006600;">setFrom</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'somebody@example.com'</span>, <span style="color:#FF0000;">'Ein Versender'</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;"><span style="color:#0000FF;">$mail</span>-&gt;<span style="color:#006600;">addTo</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'somebody_else@example.com'</span>, <span style="color:#FF0000;">'Ein Empfänger'</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:#0000FF;">$mail</span>-&gt;<span style="color:#006600;">setSubject</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'TestBetreff'</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;"><span style="color:#0000FF;">$mail</span>-&gt;<span style="color:#006600;">send</span><span style="color:#006600; font-weight:bold;">&#40;</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>
<p></p>
<p>Die Methoden zum Setzen des Textes, des Absenders, des Empfängers und des Betreffs sind leicht nachzuvollziehen. Der Versand erfolgt hierbei über die normale mail() Funktion von PHP. </p>
<p>Für den Versand von E-Mails per SMTP müssen vor dem Erstellen des Zend_Mail Objektes noch folgende Zeilen eingefügt werden (am besten in der Bootstrap Datei oder, in unserem Falle, in der "settings.php" Datei):</p>
<div class="igBar"><span id="lphp-29"><a href="#" onclick="javascript:showCodeTxt('php-29'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-29">
<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;">$tr</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Mail_Transport_Smtp<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'mail.example.com'</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;">Zend_Mail::<span style="color:#006600;">setDefaultTransport</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$tr</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Leider ist es derzeit noch nicht möglich, E-Mail mit SMTP Authentifizierung zu versenden. Wer dies dringend benötigt, sollte sich einmal <a href="http://framework.zend.com/issues/browse/ZF-458">diesen Patch</a> anschauen, der hoffentlich bald implementiert wird.</p>
<h3><a name="wichtig">Wichtiger Hinweis</a></h3>
<p>Da die Einrichtung eines Mailservers unter Windows XP den Rahmen dieses Tutorials sprengen würde, gehe ich darauf nicht weiter ein. D.h. wenn du Zend_Mail so verwendest, wie hier angegeben, ist es wahrscheinlich, dass keine Mails versendet werden und du somit das Gefühl bekommst, dass Zend_Mail nicht funktioniert. Ich empfehle daher, das Projekt auf einem Server einzurichten, auf dem Mailversand möglich ist</p>
<h3><a name="vorueberlegungen1">Vorüberlegungen für Zend_Mail</a></h3>
<p>Die sinnvollste Möglichkeit für den Versand einer E-Mail sind nach dem Schreiben eines neuen Kommentars oder nach dem Schreiben eines neuen Artikels. Nach diesen Aktionen könnte sich der Administrator des TravelloBlogs per E-Mail informieren lassen. </p>
<p>Es macht durchaus Sinn, die Standard Empfänger- und Versandadressen für diese E-Mails an einer zentralen Stelle zu speichern. Dafür bietet sich natürlich unsere "settings.ini" Datei im Verzeichnis "/application/config" an:</p>
<div class="codebox">
<pre>
mail.defaultsender    = travelloblog@my-project.com
mail.defaultrecipient = admin@my-project.com
</pre>
</div>
<p>Da wir für unser Beispiel den normalen Versand und nicht den Versand per SMTP verwenden möchten, sind keine weiteren Arbeiten erforderlich. Falls du doch den SMTP Versand bevorzugst, kannst du in der "settings.php" noch folgende Zeilen hinzufügen:</p>
<div class="igBar"><span id="lphp-30"><a href="#" onclick="javascript:showCodeTxt('php-30'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-30">
<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;">$tr</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Mail_Transport_Smtp<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">mail</span>-&gt;<span style="color:#006600;">defaultsender</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;">Zend_Mail::<span style="color:#006600;">setDefaultTransport</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$tr</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Wie schon erwähnt, ist aber derzeit ein Versand mit SMTP Authentifizierung noch nicht möglich.</p>
<h3><a name="commentcontroller">CommentController anpassen</a></h3>
<p>Wir möchten uns als erstes per E-Mail über neue Kommentare informieren lassen. Es liegt also nahe, den Versand der E-Mail nach dem Speichern des neuen Kommentars durchführen zu lassen. Das wäre also somit in der Methode saveData im CommentController. Um diese Methode nicht zu unübersichtlich werden zu lassen, führen wir als erste eine neue private Methode sendMail im CommentController ein:</p>
<div class="igBar"><span id="lphp-31"><a href="#" onclick="javascript:showCodeTxt('php-31'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-31">
<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;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; private <span style="color:#000000; font-weight:bold;">function</span> sendMail<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$data</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:#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; &nbsp; &nbsp; <span style="color:#0000FF;">$config</span> = Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'config'</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$mailView</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_View<span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; <span style="color:#0000FF;">$mailView</span>-&gt;<span style="color:#006600;">setScriptPath</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">framework</span>-&gt;<span style="color:#006600;">view_dir</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; &nbsp; &nbsp; <span style="color:#0000FF;">$mailView</span>-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'comment'</span>, <span style="color:#0000FF;">$data</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$bodyText</span> = <span style="color:#0000FF;">$mailView</span>-&gt;<span style="color:#006600;">render</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'mail/new_comment.php'</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$mail</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Mail<span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; <span style="color:#0000FF;">$mail</span>-&gt;<span style="color:#006600;">setBodyText</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$bodyText</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; &nbsp; &nbsp; <span style="color:#0000FF;">$mail</span>-&gt;<span style="color:#006600;">setFrom</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">mail</span>-&gt;<span style="color:#006600;">defaultsender</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; &nbsp; &nbsp; <span style="color:#0000FF;">$mail</span>-&gt;<span style="color:#006600;">addTo</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">mail</span>-&gt;<span style="color:#006600;">defaultrecipient</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; &nbsp; &nbsp; <span style="color:#0000FF;">$mail</span>-&gt;<span style="color:#006600;">setSubject</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'New comment'</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//&nbsp; &nbsp; &nbsp; &nbsp; $mail-&gt;send();</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:#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;">&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;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<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>
<p></p>
<p>Was passiert hier? Zuerst holen wir unser Zend_Config Objekt aus dem Objektspeicher. Für das Erstellen des Mailtextesverwenden wir eine neuen Instanz von Zend_View. Das ist einfacher, als per PHP den Mailtext in einem String zusammen zu basteln. Wenn wir den Mailtext erstellt haben, können wir unser Zend_Mail Objekt erstellen und die verschiedenen Elemente mit Inhalten versehen.</p>
<p>Das abschließende Senden der E-Mail habe ich bewusst auskommentiert. Wenn auf deinem Entwicklungsrechner kein Mailserver installiert ist, bekommst du sonst entsprechende Fehlermeldung. Wenn du aber einen Mailserver verfügbar hast (was unter Unix / Linux wohl der Fall aus, aber damit kenne ich mich nicht besonders aus), dann kannst du die Zeile natürlich wieder einkommentieren. </p>
<p>Damit das aber funktionieren kann, benötigen wir noch zwei Dinge. Zum einen müssen wir in der Methode saveData im CommentController noch die Methode sendMail aufrufen:</p>
<div class="igBar"><span id="lphp-32"><a href="#" onclick="javascript:showCodeTxt('php-32'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-32">
<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;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; private <span style="color:#000000; font-weight:bold;">function</span> saveData<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$data</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:#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; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'com_id'</span><span style="color:#006600; font-weight:bold;">&#93;</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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:#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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">else</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:#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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'com_date'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <a href="http://www.php.net/date"><span style="color:#000066;">date</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Y-m-d H:i:s'</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; &nbsp; &nbsp; &nbsp; &nbsp; </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:#0000FF;">$com_id</span> = <span style="color:#0000FF;">$comment</span>-&gt;<span style="color:#006600;">insert</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$data</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; &nbsp; &nbsp; &nbsp; &nbsp; </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:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'com_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF;">$com_id</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; </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:#0000FF;">$this</span>-&gt;<span style="color:#006600;">sendMail</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$data</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; &nbsp; &nbsp; &nbsp; &nbsp; </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:#0000FF;">$art_id</span> = <span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'com_art_id'</span><span style="color:#006600; font-weight:bold;">&#93;</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:#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;">&nbsp; &nbsp; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;">&nbsp;</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;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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>
<p></p>
<p>Achte bitte darauf, dass du vor dem Aufruf von sendMail() noch die ID des neuen Kommentars an das Array $data übergibst.</p>
<p>Als nächstes brauchst du noch das Template "new_comment.php", welches du im Verzeichnis "/application/views/mail" anlegst:</p>
<div class="igBar"><span id="lphp-33"><a href="#" onclick="javascript:showCodeTxt('php-33'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-33">
<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;">A <span style="color:#000000; font-weight:bold;">new</span> comment was saved in the TravelloBlog. Here are the details:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">==================================================================</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">escape</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">comment</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'com_title'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> . <span style="color:#FF0000;">"<span style="color:#000099; font-weight:bold;">\n</span>"</span>; <span style="color:#000000; font-weight:bold;">?&gt;</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;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <a href="http://www.php.net/str_pad"><span style="color:#000066;">str_pad</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'-'</span>, <a href="http://www.php.net/strlen"><span style="color:#000066;">strlen</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">comment</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'com_title'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#FF0000;">'-'</span><span style="color:#006600; font-weight:bold;">&#41;</span> . <span style="color:#FF0000;">"<span style="color:#000099; font-weight:bold;">\n</span>"</span>; <span style="color:#000000; font-weight:bold;">?&gt;</span></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;">From&nbsp; &nbsp; : <span style="color:#000000; font-weight:bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/strlen"><span style="color:#000066;">strlen</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">comment</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'com_nickname'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>&gt; <span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">escape</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">comment</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'com_nickname'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> : <span style="color:#FF0000;">"anonymous"</span>; <span style="color:#000000; font-weight:bold;">?&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">E-<a href="http://www.php.net/mail"><span style="color:#000066;">Mail</span></a>&nbsp; : <span style="color:#000000; font-weight:bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/strlen"><span style="color:#000066;">strlen</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">comment</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'com_mail'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>&gt; <span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">escape</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">comment</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'com_mail'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> : <span style="color:#FF0000;">"-"</span>; <span style="color:#000000; font-weight:bold;">?&gt;</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;">Homepage: <span style="color:#000000; font-weight:bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/strlen"><span style="color:#000066;">strlen</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">comment</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'com_homepage'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>&gt; <span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">escape</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">comment</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'com_homepage'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> : <span style="color:#FF0000;">"-"</span>; <span style="color:#000000; font-weight:bold;">?&gt;</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/date"><span style="color:#000066;">Date</span></a>&nbsp; &nbsp; : <span style="color:#000000; font-weight:bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">escape</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">comment</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'com_date'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#000000; font-weight:bold;">?&gt;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Comment:</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;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <a href="http://www.php.net/wordwrap"><span style="color:#000066;">wordwrap</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">escape</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">comment</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'com_text'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#CC66CC;color:#800000;">66</span>, <span style="color:#FF0000;">"<span style="color:#000099; font-weight:bold;">\n</span>"</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#000000; font-weight:bold;">?&gt;</span></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;">==================================================================</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Change: http:<span style="color:#FF9933; font-style:italic;">//travelloblog/comment/change/&lt;?php echo $this-&gt;escape($this-&gt;comment['com_id']); ?&gt;</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;">Delete: http:<span style="color:#FF9933; font-style:italic;">//travelloblog/comment/delete/&lt;?php echo $this-&gt;escape($this-&gt;comment['com_id']); ?&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">================================================================== </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Die Ausgabe kannst du natürlich nach deinen Wünschen umstricken, aber ich denke, das Prinzip sollte klar sein. Du verwendest halt ein ganz normales PHP Skript für die Erstellung des Mailtextes, welches dann von Zend_View aufgerufen und verarbeitet wird.</p>
<h3><a name="uebung1">Übung 1: Zend_Mail für neue Artikel</a></h3>
<p>Als erste Übung bitte ich dich, auch für neue Artikel eine neue Mail zu versenden. Dafür benötigst du neben dem Mailtemplate natürlich auch wieder eine Funktion zum Versenden der Mail und musst den Versand in die entsprechende Methode im ArticleController aufrufen. </p>
<p>Natürlich kannst du dir auch noch weitere Aktionen überlegen, nach dem du eine Mail versenden möchtest. Dies wäre z.B. auch nach dem Anlegen von Kategorien oder Tags bzw. nach dem Ändern oder Löschen von Artikeln und Kommentaren denkbar.</p>
<p>Zur Kontrolle lade dir den aktuellen Stand des Tutorials runter. Dann kannst du deine Ergebnisse damit vergleichen.</p>
<h3><a name="zend_log">Zend_Log</a></h3>
<p>Auch für die Komponente Zend_Log empfehle ich zuerst den Blick in das entsprechende <a href="http://framework.zend.com/manual/de/zend.log.html]">Kapitel im Zend Framework Manual</a> Dies ist zwar noch recht knapp gehalten, beinhaltet aber schon alle wesentlichen Informationen.</p>
<p>Zend_Log kann im Gegensatz zu den meisten anderen Komponenten des Zend Frameworks nicht direkt instanziert werden. Über statische Aufrufe können aber verschiedene, auch mehrfache Logdateien erstellt werden. Dabei stehen mehrere Adapter für das Speichern der Logdaten in Dateien, in einer Datenbank oder in der Konsole zur Verfügung.</p>
<p>Die Verwendung ist recht einfach. Zuerst muss ein zu erstellendes Log unter Angabe des Adapters registriert werden. Danach kann über eine statische Methode überall, wo es notwendig erscheint, geloggt werden, was das Zeug hält. Dieses Beispiel aus dem Manual verwendet den Datei Adapter:</p>
<div class="igBar"><span id="lphp-34"><a href="#" onclick="javascript:showCodeTxt('php-34'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-34">
<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:#FF9933; font-style:italic;">// Dateilog registrieren</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Zend_Log::<span style="color:#006600;">registerLogger</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">new</span> Zend_Log_Adapter_File<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'/logs/simple.txt'</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// einfache Nachricht registrieren</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;">Zend_Log::<a href="http://www.php.net/log"><span style="color:#000066;">log</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Erste Protokollnachricht.'</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;</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:#FF9933; font-style:italic;">// schwerwiegenden Fehler registrieren</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Zend_Log::<a href="http://www.php.net/log"><span style="color:#000066;">log</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Ein schwerer Fehler ist aufgetreten.'</span>, Zend_Log::<span style="color:#006600;">LEVEL_SEVERE</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Es lassen sich auch mehrere unabhängige Logs erstellen. Dann wird beim Aufruf von Zend_Log::registerLogger noch ein Name übergeben. Und beim Aufruf von Zend_Log::log muss dieser Name ebenfalls angegeben werden:</p>
<div class="igBar"><span id="lphp-35"><a href="#" onclick="javascript:showCodeTxt('php-35'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-35">
<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:#FF9933; font-style:italic;">// zwei Logs erstellen</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Zend_Log::<span style="color:#006600;">registerLogger</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">new</span> Zend_Log_Adapter_File<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'/logs/framework.txt'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#FF0000;">'Datei'</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;">Zend_Log::<span style="color:#006600;">registerLogger</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">new</span> Zend_Log_Adapter_Console<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#FF0000;">'Konsole'</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;</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:#FF9933; font-style:italic;">// Fehler im Dateilog aufnehmen</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Zend_Log::<a href="http://www.php.net/log"><span style="color:#000066;">log</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Ein schwerer Fehler ist aufgetreten.'</span>, Zend_Log::<span style="color:#006600;">LEVEL_SEVERE</span>, <span style="color:#FF0000;">'Datei'</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// Fehler im Konsolenlog aufnehmen</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;">Zend_Log::<a href="http://www.php.net/log"><span style="color:#000066;">log</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Ein schwerer Fehler ist aufgetreten.'</span>, Zend_Log::<span style="color:#006600;">LEVEL_SEVERE</span>, <span style="color:#FF0000;">'Konsole'</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Hierbei musst du aber darauf achten, dass du immer eine der möglichen Protokollstufen als zweiten Parameter angibst. Eine Übersicht über die <a href="http://framework.zend.com/manual/de/zend.log.log-levels.html">Protokollstufen</a> findest du im Manual.</p>
<h3><a name="vorueberlegungen2">Vorüberlegung für Zend_Log</a></h3>
<p>Im Gegensatz zu Zend_Mail müssen wir für die Registrierung unseres Logs wieder die "settings.php" Datei bemühen, weil wir dort an zentraler Stelle das Log registrieren können. </p>
<p>Welche Informationen wirklich loggenswert sind, darüber gehen die Meinung weit auseinander. Wichtig ist es z.B. Fehler in einem zentralen Log zu speichern, das der Entwickler bei Bedarf dann genau untersuchen kann. </p>
<p>Da wir uns in unserem Projekt bisher jedoch noch nicht intensiv mit dieser Thematik befasst haben, möchte ich vorschlagen, dass wir alle Änderungen an der Datenbank zentral in einer Datei speichern. Also registrieren wir unser Datenbank Log als erstes am Ende unserer "settings.php" Datei:</p>
<div class="igBar"><span id="lphp-36"><a href="#" onclick="javascript:showCodeTxt('php-36'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-36">
<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;">Zend_Log::<span style="color:#006600;">registerLogger</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">new</span> Zend_Log_Adapter_File<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">framework</span>-&gt;<span style="color:#006600;">log_dir</span> .<span style="color:#FF0000;">'/database.txt'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#FF0000;">'Database'</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Natürlich müssen wir dieses neue Verzeichnis auch noch anlegen und in unsere "settings.ini" Datei deklarieren:</p>
<div class="codebox">
<pre>
framework.log_dir         = /path/to/travelloblog/logs
</pre>
</div>
<p>bzw.</p>
<div class="codebox">
<pre>
framework.log_dir         = e:\travelloblog\logs
</pre>
</div>
<p>Damit kein Unbefugter auf die Logs zugreifen kann, müssen wir diesen Zugriff über den Webserver einschränken. Dafür brauchst du einfach nur die Datei ".htaccess" aus dem Verzeichnis "/application" in das neue Verzeichnis "/log" kopieren. Das war es dann an Vorbereitungen.</p>
<h3><a name="datenbankaenderungen">Datenbankänderungen loggen</a></h3>
<p>Wir beginnen damit, die Datenbankänderungen für unsere Artikel zu loggen. Dafür öffne bitte die ArticleController Datei und suche die saveData Methode. Dort fügst du direkt hinter den Schreibzugriffen auf die Datenbank die Zeile für das Loggen der Aktion ein:</p>
<div class="igBar"><span id="lphp-37"><a href="#" onclick="javascript:showCodeTxt('php-37'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-37">
<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;">&nbsp; &nbsp; private <span style="color:#000000; font-weight:bold;">function</span> saveData<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$data</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:#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; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art_id'</span><span style="color:#006600; font-weight:bold;">&#93;</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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; </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:#0000FF;">$row</span>-&gt;<span style="color:#006600;">save</span><span style="color:#006600; font-weight:bold;">&#40;</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;</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; Zend_Log::<a href="http://www.php.net/log"><span style="color:#000066;">log</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Article '</span> . <span style="color:#0000FF;">$art_id</span> . <span style="color:#FF0000;">' updated'</span>, Zend_Log::<span style="color:#006600;">LEVEL_INFO</span>, <span style="color:#FF0000;">'Database'</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; &nbsp; &nbsp; <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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">else</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:#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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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; </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:#0000FF;">$art_id</span> = <span style="color:#0000FF;">$article</span>-&gt;<span style="color:#006600;">insert</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$insertData</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; &nbsp; &nbsp; &nbsp; &nbsp; </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; Zend_Log::<a href="http://www.php.net/log"><span style="color:#000066;">log</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Article '</span> . <span style="color:#0000FF;">$art_id</span> . <span style="color:#FF0000;">' created'</span>, Zend_Log::<span style="color:#006600;">LEVEL_INFO</span>, <span style="color:#FF0000;">'Database'</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; &nbsp; &nbsp; &nbsp; &nbsp; </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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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:#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;">&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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>In der doDeleteAction Methode stellst du dann noch sicher, dass auch das Löschen von Artikel geloggt wird:</p>
<div class="igBar"><span id="lphp-38"><a href="#" onclick="javascript:showCodeTxt('php-38'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-38">
<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;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> doDeleteAction<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$article</span>-&gt;<span style="color:#006600;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$where</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; Zend_Log::<a href="http://www.php.net/log"><span style="color:#000066;">log</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Article '</span> . <span style="color:#0000FF;">$art_id</span> . <span style="color:#FF0000;">' deleted'</span>, Zend_Log::<span style="color:#006600;">LEVEL_INFO</span>, <span style="color:#FF0000;">'Database'</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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:#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;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Jetzt rufe einmal das TravelloBlog in deinem Browser auf und ändere ein paar Artikel, erstelle einen neuen Artikel oder lösche einen bestehenden. Dein Log sollte dann in etwas so aussehen.</p>
<div class="codebox">
<pre>
Article 3 updated, INFO
Article 3 updated, INFO
Article 2 updated, INFO
Article 8 created, INFO
Article 8 deleted, INFO
</pre>
</div>
<p>Das war es auch schon. Dir steht mit Zend_Log auf jeden Fall eine gute Möglichkeit bereit, individuelle Logs für dein Projekt einzurichten und zu verwalten. Zum Beispiel wäre es noch denkbar, auch einen Zeitstempel mit zu loggen oder beim Loggen sehr schwerwiegender Fehler zeitgleich eine E-Mail an dem Administrator zu versenden. Der Fantasie sind da fast keine Grenzen gesetzt.</p>
<h3><a name="uebung2">Übung 2: Zend_Log für Kommentare, Tags und Kategorien</a></h3>
<p>Als zweite Übung bitte ich dich, auch für Kommentare, Tags und Kategorien entsprechende Meldungen in das Log zu schreiben. Wenn du möchtest, kannst du für jede Entität auch ein eigenes Log erstellen. Du kannst aber auch alle Datenbankänderungen zentral in einem Datenbanklog speichern.</p>
<p>Zur Kontrolle lade dir den aktuellen Stand des Tutorials runter. Dann kannst du deine Ergebnisse damit vergleichen.</p>
<h3><a name="download">Download</a></h3>
<p>Der aktuelle Stand des Tutorials nach diesem sechsten Teil kann herunter geladen werden. Hier sind auch alle Templates enthalten. Die Textdateien "empty.txt" in einigen Verzeichnissen habe ich nur angelegt, weil mein Winzip keine leeren Verzeichnisse im Zip Archiv anlegt:</p>
<ul>
<li><a href="http://www.ralfeggert.de/zfw/version-0.11.zip">http://www.ralfeggert.de/zfw/version-0.11.zip</a></li>
</ul>
<p>Die Zip Datei enthält nicht die aktuelle Version des Zend Frameworks. Dies musst du bitte selber in das entsprechende Verzeichnis kopieren. </p>
<h3><a name="zusammenfassung">Zusammenfassung</a></h3>
<p>In diesem elften Teil des Zend Framework Tutorials haben wir die beiden nützlichen Komponenten <strong>Zend_Mail</strong> für das Versenden von E-Mails und <strong>Zend_Log</strong> für das Loggen von Informationen kennen gelernt. Auch wenn Windows Nutzer die Funktionsweise von Zend_Mail auf ihrem lokalen Entwicklungsrechner evtl. nicht zu 100% testen konnten, hoffe ich, dass das Prinzip jedoch klar geworden ist.</p>
<p>Nach diesem etwas kürzeren Kapitel kommen wir im nächsten Teil des Zend Framework Tutorials zu einem sehr spannenden Thema: das Versenden und Empfangen von Trackbacks mit Hilfe von <strong>Zend_Http_Client</strong>.</p>
<h3><a name="changelog">Change Log</a></h3>
<p>An dieser Stelle werden Änderungen an diesem Tutorial Teil zusammengefasst, die nach dem Ersterscheinen (30.10.2006) notwendig waren, z.B. durch neuere Versionen des Zend Frameworks oder Änderungen am Konzept des Tutorials oder den Anforderungen an unser TravelloBlog.</p>
<ul>
<li>05.11.2006: Tutorial für Release 0.2.0 aktualisiert</li>
</ul>
<h3><a name="navigation">Navigation</a></h3>
<ul>
<li><a href="http://www.ralfeggert.de/2006/10/24/zend-framework-tutorial-zend_cache/">Zurück zu Teil 10: Sinnvoll cachen mit Zend_Cache</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ralfeggert.de/2006/10/30/zend-framework-tutorial-zend_log-zend_mail/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Zend Framework Tutorial Teil 10: Sinnvoll cachen mit Zend_Cache</title>
		<link>http://www.ralfeggert.de/2006/10/24/zend-framework-tutorial-zend_cache/</link>
		<comments>http://www.ralfeggert.de/2006/10/24/zend-framework-tutorial-zend_cache/#comments</comments>
		<pubDate>Tue, 24 Oct 2006 05:18:48 +0000</pubDate>
		<dc:creator>Ralf Eggert</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.ralfeggert.de/2006/10/24/zend-framework-tutorial-zend_cache/</guid>
		<description><![CDATA[Im neunten Teil vom Zend Framework Tutorial haben wir die Zend_Filter Komponente für das Filtern von Benutzereingaben kennen und anwenden gelernt. Zudem hast du in einer umfangreicheren Übung (so hoffe ich zumindest) die Kommentarfunktion für unser TravelloBlog realisiert. Wenn du die ersten neun Teile noch nicht gelesen hast, hole dies bitte schnell nach.
In diesem zehnten [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ralfeggert.de/2006/10/16/zend-framework-tutorial-zend_filter_input/">Im neunten Teil</a> vom <strong>Zend Framework Tutorial</strong> haben wir die Zend_Filter Komponente für das Filtern von Benutzereingaben kennen und anwenden gelernt. Zudem hast du in einer umfangreicheren Übung (so hoffe ich zumindest) die Kommentarfunktion für unser TravelloBlog realisiert. Wenn du die ersten neun Teile noch nicht gelesen hast, <a href="http://www.ralfeggert.de/2006/08/26/einfuehrung-und-anforderungen/#aufbau">hole dies bitte schnell nach</a>.</p>
<p>In diesem zehnten Teil des Zend Framework Tutorials werde ich Dir die Komponente <strong>Zend_Cach</strong>e vorstellen, mit der du beliebige Daten cachen kannst. Dabei werden wir uns um das Cachen von Templates sowie Datenbankabfragen kümmern und so die Performance unseres TravelloBlogs stark verbessern. </p>
<p>Wenn du über neue <strong>Tutorial</strong> Teile informiert werden möchtest, abonniere am besten den <a href="http://www.ralfeggert.de/feed/">Feed</a> dieses Blogs. Dann verpasst du garantiert keinen Teil des Tutorials.</p>
<p><strong>Wichtig</strong>: Dieses Tutorial setzt die Zend Framework Preview Version 0.2.0 voraus und kann bei der Verwendung einer aktuelleren Version aus dem SVN unter Umständen nicht zu 100% funktionieren. </p>
<p><span id="more-70"></span></p>
<h3>Inhaltsverzeichnis</h3>
<ul>
<li><a href="#zend_cache">Zend_Cache</a></li>
<li><a href="#vorueberlegungen">Vorüberlegungen</a></li>
<li><a href="#startseite_cachen">Startseite cachen</a></li>
<li><a href="#artikel_cachen">Artikelseite cachen</a></li>
<li><a href="#cache_loeschen">Cache Dateien löschen</a></li>
<li><a href="#datenbankabfragen">Datenbankabfragen cachen</a></li>
<li><a href="#uebung">Übung: Caching für weitere Controller</a></li>
<li><a href="#download">Download</a></li>
<li><a href="#zusammenfassung">Zusammenfassung</a></li>
<li><a href="#changelog">Change log</a></li>
<li><a href="#navigation">Navigation</a></li>
<li><a href="#comments">Kommentare</a></li>
</ul>
<h3><a name="zend_cache">Zend_Cache</a></h3>
<p>Zum Einstieg empfehle ich wie immer als ersten den Blick in <a href="http://framework.zend.com/manual/de/zend.cache.html">das Zend_Cache Kapitel im Manual</a>, in dem die Verwendungsmöglichkeiten von Zend_Cache umfassend beschrieben ist.</p>
<p>Bei der Verwendung von <strong>Zend_Cache</strong> ist zuallererst zwischen dem Frontend und dem Backend zu unterscheiden. Die Zend_Cache Frontends kümmern sich darum, <strong>was</strong> gecached werden soll, während sich die Zend_Cache Backends darum kümmern, <strong>wie</strong> gecached werden soll.</p>
<p>Zend_Cache bietet von Haus aus bereits Frontends für das Cachen von Ausgaben, Funktionen, Objekten, Dateien und kompletten Seiten. Dadurch ist Zend_Cache sehr flexibel gestaltet, so dass du dich nicht nur auf das Cachen von Templates beschränken musst, sondern auch Klassen, Datenbankabfragen oder dynamisch erstellte Dateien bequem cachen kannst.</p>
<p>Auch beim Backend bietet Zend_Cache mehrere Optionen. So können die gecacheden Daten als Dateien, in einer Sqlite Datenbank, in einem Memcache Server oder im Shared Memory gespeichert werden. Während für einige Fällen das Cachen in Dateien sinnvoll und ausreichend ist, wäre in anderen Fällen wiederum das Cachen im Shared Memory sinnvoller. </p>
<p>Für weitere Details empfehle ich noch mal den Blick ins Manual, da das Kapitel über Zend_Cache recht umfangreich ist. Da es dort auch viele Beispiele gibt, spare ich mir diese an dieser Stelle. Nach einigen Vorüberlegungen steigen wir eh gleich direkt in die Anwendung ein.</p>
<h3><a name="vorueberlegungen">Vorüberlegungen</a></h3>
<p>Als erstes überlegen wir einmal, welche Daten wir überhaupt sinnvoller Weise cachen wollen. Wenn wir das entschieden haben, machen wir uns darüber Gedanken, wie wir diese Daten cachen möchten.</p>
<p>Als erster Anwendungsfall kommt dir sicherlich das Cachen der Ausgaben, also der Templates in den Sinn. Als Frontend würde sich dafür Zend_Cache_Frontend_Output und als Backend Zend_Cache_Backend_File anbieten. </p>
<p>Ein weitere Anwendungsfall wären Datenbankabfragen, die auf jeder bzw. auf sehr vielen Seiten unseres TravelloBlogs durchgeführt werden. Da würden sich z.B. die Datenbankabfragen für die Navigation oder unsere Tagwolke anbieten. Als Frontend würden sich hierfür Zend_Cache_Frontend_Core anbieten und als Backend würde ich wieder  Zend_Cache_Backend_File wählen. </p>
<p>Um unsere Cache Dateien speichern zu können, benötigen wir ein weiteres Verzeichnis. Lege also bitte das Verzeichnis "/public/tmp" an und platziere dort eine .htaccess Datei mit folgendem Inhalt, um eine direkten Aufruf der Cache Dateien über den Browser zu vermeiden:</p>
<div class="codebox">
<pre>
deny from all
</pre>
</div>
<p>Es macht Sinn, das Verzeichnis auch in unsere "settings.ini" Datei aufzunehmen, damit wir über unser Zend_Config Objekt überall darauf zugreifen können. Deshalb füge in die "settings.ini" noch folgenden Eintrag für das Cache Verzeichnis hinzu:</p>
<div class="codebox">
<pre>
framework.cache_dir       = e:\travelloblog\public\tmp
</pre>
</div>
<h3><a name="startseite_cachen">Startseite cachen</a></h3>
<p>Als erstes benötigen wir ein Zend_Cache Objekt für das Speichern der Templates in Dateien. Dazu öffne die Datei "settings.php" im Verzeichnis "/application/config" und füge dort folgenden Code ans Ende an.</p>
<div class="igBar"><span id="lphp-51"><a href="#" onclick="javascript:showCodeTxt('php-51'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-51">
<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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$frontendOptions</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'lifeTime'</span> =&gt; <span style="color:#CC66CC;color:#800000;">10</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:#0000FF;">$backendOptions</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'cacheDir'</span> =&gt; <span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">framework</span>-&gt;<span style="color:#006600;">cache_dir</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;"><span style="color:#0000FF;">$templateCache</span> = Zend_Cache::<span style="color:#006600;">factory</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Output'</span>, <span style="color:#FF0000;">'File'</span>, <span style="color:#0000FF;">$frontendOptions</span>, <span style="color:#0000FF;">$backendOptions</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;">Zend::<span style="color:#006600;">register</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'templateCache'</span>, <span style="color:#0000FF;">$templateCache</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;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Wir erstellen also einen Cache unter Verwendung des "Output" Frontends und des "File" Backends. Als Parameter für das Frontend habe ich eine Lebenszeit für den Cache von 10 Sekunden angegeben. Auf einem Produktiv Server sollte dieser Wert natürlich höher gesetzt werden. An das Backend übergeben wir nur das erstellte Cache Verzeichnis.</p>
<div class="textbox">
<strong>Hinweis</strong></p>
<p>Natürlich kannst du die Angaben zum Frontend und Backend sowie deren Optionen auch in unserer zentralen Konfigurationsdatei "settings.ini" verwalten und dann beim Aufruf von Zend_Cache::factory() übergeben. Ich habe darauf an dieser Stelle einfach verzichtet.
</p></div>
<p>Widmen wir uns nun dem Cachen unserer Startseite, die wohl am häufigsten aufgerufen werden wird. Öffne also bitte den die Datei "ArticleController.php" und suche dort nach der Methode indexAction. Diese änderst du nun wie folgt ab:</p>
<div class="igBar"><span id="lphp-52"><a href="#" onclick="javascript:showCodeTxt('php-52'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-52">
<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;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> indexAction<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_cacheId = <span style="color:#FF0000;">'index'</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; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#0000FF;">$this</span>-&gt;_cacheTpl = Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'templateCache'</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;_cacheId<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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$article</span> = <span style="color:#000000; font-weight:bold;">new</span> ArticleModel<span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; &nbsp; &nbsp; </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:#0000FF;">$order</span>&nbsp; = <span style="color:#FF0000;">'art_cdate DESC'</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:#0000FF;">$rowset</span> = <span style="color:#0000FF;">$article</span>-&gt;<span style="color:#006600;">fetchAll</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">null</span>, <span style="color:#0000FF;">$order</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; &nbsp; &nbsp; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$data</span> = <span style="color:#0000FF;">$rowset</span>-&gt;<span style="color:#006600;">toArray</span><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_view-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'title'</span>, <span style="color:#FF0000;">'TravelloBlog - List of articles'</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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_view-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'articles'</span>, <span style="color:#0000FF;">$data</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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_view-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'subtemplate'</span>, <span style="color:#FF0000;">'article/index.php'</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; &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;">&nbsp; &nbsp; <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;">&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;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<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>
<p></p>
<p>Als erstes legen wir eine Cache Id fest, unter der unser Template gecached werden soll. Wir speichern diese Cache Id in der Klasseneigenschaft $this->_cacheId ab, damit wir später noch darauf zugreifen können. </p>
<p>Danach versuchen wir die Cache Datei für diese Cache Id zu lesen und in der  Klasseneigenschaft $this->_cacheTpl abzulegen. Wenn keine gültige Cache Datei gefunden werden konnte, wird false zurückgegeben und die weiteren Zeilen in der if-Bedingung werden ausgeführt. Falls eine gültige Cache Datei gefunden werden konnte, wird dieser Teil nicht ausgeführt. Das war es auch schon im ArticleController für die Startseite.</p>
<p>Wie du dich sicher noch erinnern kannst, haben wir die Ausgabe unsere Templates an eine zentrale Stelle ausgelagert. Und zwar in den Destruktor unserer Travello_Controller_Action Klasse. Als öffne bitte die Datei "Action.php" im Verzeichnis "/library/zf/Travello/Controller/". Der Vollständigkeit halber erstellen wir zuerst die beiden in der indexAction Methode vom ArticleController verwendeten Klasseneigenschaften $this->_cacheId und $this->_cacheTpl und ändern die Methode __destruct wie folgt ab:</p>
<div class="igBar"><span id="lphp-53"><a href="#" onclick="javascript:showCodeTxt('php-53'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-53">
<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;">abstract <span style="color:#000000; font-weight:bold;">class</span> Travello_Controller_Action extends Zend_Controller_Action</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;">&#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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; protected <span style="color:#0000FF;">$_cacheTpl</span> = <span style="color:#000000; font-weight:bold;">false</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; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; protected <span style="color:#0000FF;">$_cacheId</span> = <span style="color:#000000; font-weight:bold;">false</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; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; protected <span style="color:#0000FF;">$_cacheTag</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</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; </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;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> __destruct<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#0000FF;">$this</span>-&gt;_cacheTpl<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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_view-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'navigation'</span>, <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getNavigation</span><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_view-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'tagcloud'</span>, <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getTagcloud</span><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_view-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'lastcomments'</span>, <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getComments</span><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; &nbsp; &nbsp; </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:#0000FF;">$this</span>-&gt;_cacheTpl = <span style="color:#0000FF;">$this</span>-&gt;_view-&gt;<span style="color:#006600;">render</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;_template<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; &nbsp; &nbsp; &nbsp; &nbsp; </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:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;_cacheId<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; &nbsp; &nbsp; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'templateCache'</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">save</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;_cacheTpl, <span style="color:#0000FF;">$this</span>-&gt;_cacheId, <span style="color:#0000FF;">$this</span>-&gt;_cacheTag<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; &nbsp; &nbsp; &nbsp; &nbsp; <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;">&nbsp; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$this</span>-&gt;_cacheTpl;</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:#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;"><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:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Zuerst wird anhand von $this->_cacheTpl geprüft, ob keine Cache Datei gelesen werden konnte. Falls nicht werden die weiteren Templatevariablen zugeordnet sowie die Ausgabe des Templates an $this->_cacheTpl übergeben. </p>
<p>Danach wird geprüft, ob eine Cache Id gesetzt worden ist und bei Bedarf wird das Template in der Cache Datei für unsere angegebene Cache Id gespeichert. Zum Schluss kann dann einfach $this->_cacheTpl ausgegeben werden, weil dort entweder die gelesenen Cache Daten oder das eben gerenderte Template enthalten ist. </p>
<div class="textbox">
<strong>Hinweis</strong></p>
<p>Die bereits eingeführte, aber noch nicht erläuterte Klasseneigenschaft $this->_cacheTag benötigen wir an dieser Stelle eigentlich noch nicht. Der Sinn wird erst im nächsten Abschnitt erläutert.
</p></div>
<p>Bevor wir uns das Ergebnis nun anschauen können, solltest du noch in deinem Haupttemplate einen Zeitstempel einbauen, damit man auch sehen kann, ob das Cachen wirklich geklappt hat. Also öffne die Datei "main.php" im Verzeichnis "/application/views" und ändere den Footer wie folgt ab:</p>
<div class="igBar"><span id="lphp-54"><a href="#" onclick="javascript:showCodeTxt('php-54'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-54">
<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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;div id=<span style="color:#FF0000;">"footer"</span>&gt;</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;">TravelloBlog <span style="color:#CC66CC;color:#800000;">2006</span> - Last update: <span style="color:#000000; font-weight:bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <a href="http://www.php.net/date"><span style="color:#000066;">date</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Y-m-d H:i:s'</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#000000; font-weight:bold;">?&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/div&gt;</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;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Danach rufe die Startseite des TravelloBlogs auf. Du siehst unten den Zeitstempel und wenn du die Startseite vor Ablauf der 10 Sekunden erneut aufrufst, sollte sich der Zeitstempel nicht verändert haben. Alle anderen Seiten werden aber noch nicht gecached.</p>
<h3><a name="artikel_cachen">Artikelseite cachen</a></h3>
<p>Durch den Destruktor in unserer Travello_Controller_Action Klasse und durch die beiden Klasseneigenschaften $this->_cacheTpl und $this->_cacheId ist das Einführen des Cachens in allen anderen Aktionsmethoden unserer Controller nur noch ein Kinderspiel. Wir müssen lediglich eine Cache ID festlegen und die Abfrage der Cache Datei einbauen.</p>
<p>Für das Cachen eines Artikels macht es Sinn, in die Cache Id auch die Id des Artikels zu übernehmen. Ändere also als nächstes die showAction Methode im ArticleController wie folgt ab:</p>
<div class="igBar"><span id="lphp-55"><a href="#" onclick="javascript:showCodeTxt('php-55'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-55">
<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;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> showAction<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#0000FF;">$art_id</span> = <span style="color:#0000FF;">$this</span>-&gt;_getParam<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'id'</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_cacheId = <span style="color:#FF0000;">'article_show_'</span> . <span style="color:#0000FF;">$art_id</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; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_cacheTag = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'article_'</span> . <span style="color:#0000FF;">$art_id</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#0000FF;">$this</span>-&gt;_cacheTpl = Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'templateCache'</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;_cacheId<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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$article</span> = <span style="color:#000000; font-weight:bold;">new</span> ArticleModel<span style="color:#006600; font-weight:bold;">&#40;</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;</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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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:#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;">&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;">&nbsp;</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;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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>
<p></p>
<p>Wir erstellen also als erstes eine Cache Id, indem wir die aktuelle Artikel Id anhängen. Danach wird wieder versucht, eine gültige Cache Datei zu lesen. Schlägt dies fehl, werden die notwendigen Daten gelesen. Um den Rest, also das Rendern des Templates und das Speichern in einer Cache Datei kümmert sich dann wieder der Destruktor in unserer Travello_Controller_Action Klasse. </p>
<p>An dieser Stelle haben wir nun die Klasseneigenschaft $this->_cacheTag belegt und du fragst dich sicherlich nach dem Sinn. Mit Hilfe von so genannten Cache Tags kannst du bestimmte Cache Dateien auszeichnen, um sie später gezielt löschen zu können. Es macht also Sinn, alle Cache Dateien eines Artikels zu löschen, wenn sich dieser Artikel ändert oder wenn er gelöscht wird. Darum kümmern wir uns gleich im nächsten Abschnitt. </p>
<p>Die selben Änderungen führen wir nun auch für die Aktionsmethoden deleteAction durch, welche einen Artikel vor dem Löschen noch einmal zur Kontrolle anzeigt. Auch hier setzen wir den gleichen Cache Tag.</p>
<div class="igBar"><span id="lphp-56"><a href="#" onclick="javascript:showCodeTxt('php-56'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-56">
<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;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> deleteAction<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#0000FF;">$art_id</span> = <span style="color:#0000FF;">$this</span>-&gt;_getParam<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'id'</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_cacheId = <span style="color:#FF0000;">'article_delete_'</span> . <span style="color:#0000FF;">$art_id</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; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_cacheTag = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'article_'</span> . <span style="color:#0000FF;">$art_id</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#0000FF;">$this</span>-&gt;_cacheTpl = Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'templateCache'</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;_cacheId<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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$article</span> = <span style="color:#000000; font-weight:bold;">new</span> ArticleModel<span style="color:#006600; font-weight:bold;">&#40;</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;</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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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:#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;">&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;">&nbsp;</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;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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>
<p></p>
<p>Das war es auch schon. Mehr Aktionsmethoden im ArticleController benötigen kein Cachen, da es keinen Sinn macht, Formulare zu cachen. </p>
<h3><a name="cache_loeschen">Cache Dateien löschen</a></h3>
<p>Unter bestimmten Voraussetzungen macht es Sinn, bestehende aber noch nicht ungültige Cache Dateien zu löschen. Zur Demonstration ändere bitte einmal die Cache Lebenszeit in der "settings.php" Datei von 10 auf 20 Sekunden. Lasse dir dann einen Artikel anzeigen und füge einen Kommentar hinzu. Es sieht nun so aus, als wenn der Kommentar nicht gespeichert worden wäre. </p>
<p>Als müssen wir nach der Änderung eines Artikels oder nach dem Hinzufügen eines Kommentars alle Cache Dateien für diesen Artikel löschen. Hierbei kommt nun endlich auch der Cache Tag zur Anwendung.</p>
<p>Öffne also nun den CommentController und füge in der saveData Methode vor dem Redirect folgende Zeile ein:</p>
<div class="igBar"><span id="lphp-57"><a href="#" onclick="javascript:showCodeTxt('php-57'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-57">
<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;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; private <span style="color:#000000; font-weight:bold;">function</span> saveData<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$data</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:#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; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'templateCache'</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">clean</span><span style="color:#006600; font-weight:bold;">&#40;</span>Zend_Cache::<span style="color:#006600;">CLEANING_MODE_MATCHING_TAG</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'article_'</span> . <span style="color:#0000FF;">$art_id</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; &nbsp; &nbsp; Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'templateCache'</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">remove</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'index'</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; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$url</span> = getRewriteBase<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> . <span style="color:#FF0000;">'/article/show/'</span> . <span style="color:#0000FF;">$art_id</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; </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:#0000FF;">$this</span>-&gt;_redirect<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$url</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:#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;">&nbsp;</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;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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>
<p></p>
<p>In der ersten Zeile holen wir uns das Cache Objekt aus dem Objektspeicher, rufen die clean() Methode auf und übergeben den Löschmodus für das Löschen anhand von Tags sowie den Tag selber. In der zweiten neuen Zeile löschen wir den Cache für die Startseite anhand der eindeutigen Cache Id.</p>
<p>Wenn du nun erneut einen Artikel aufrufst und einen Kommentar hinzufügst, wird dieser sofort angezeigt. </p>
<p>Beide Zeilen musst du nun noch in der doDeleteAction Methode vom CommentController hinzufügen, damit auch beim Löschen eines Kommentars der Cache gelöscht wird.</p>
<div class="igBar"><span id="lphp-58"><a href="#" onclick="javascript:showCodeTxt('php-58'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-58">
<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;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; private <span style="color:#000000; font-weight:bold;">function</span> doDeleteAction<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$art_id</span> = <span style="color:#0000FF;">$row</span>-&gt;<span style="color:#006600;">comArtId</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; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'templateCache'</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">clean</span><span style="color:#006600; font-weight:bold;">&#40;</span>Zend_Cache::<span style="color:#006600;">CLEANING_MODE_MATCHING_TAG</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'article_'</span> . <span style="color:#0000FF;">$art_id</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; &nbsp; &nbsp; Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'templateCache'</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">remove</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'index'</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; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$url</span> = getRewriteBase<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> . <span style="color:#FF0000;">'/article/show/'</span> . <span style="color:#0000FF;">$art_id</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; </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:#0000FF;">$this</span>-&gt;_redirect<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$url</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:#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;">&nbsp;</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;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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>
<p></p>
<p>Der Vollständigkeit halber müssen wir nun auch im ArticleController noch die Cache Dateien nach der Änderung eines Artikels bzw. nach dem Löschen eines Artikels entfernen. Also füge die beiden Zeilen ebenfalls im ArticleController in den Methoden saveData und doDeleteAction vor dem Redirect ein.</p>
<h3><a name="datenbankabfragen">Datenbankabfragen cachen</a></h3>
<p>Jetzt möchten wir noch einen anderen Anwendungsfall betrachten. Und zwar werden bestimmte Datenbankabfragen auf jeder Seite durchgeführt. Dabei handelt es sich um das Lesen der Kategorien für die Navigation, um die Tagwolke und die letzten Kommentare. Es macht durchaus Sinn, diese Daten auch zu cachen, da wir sie sicher nicht bei jedem Seitenabruf neu laden müssen.</p>
<p>Dafür benötigen wir als erstes ein weiteres Cache Objekt, mit dem wir Methodenaufrufe einer Klasse cachen können. Füge also am Ende der "settings.php" Datei folgende Zeilen ein:</p>
<div class="igBar"><span id="lphp-59"><a href="#" onclick="javascript:showCodeTxt('php-59'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-59">
<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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$frontendOptions</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'lifeTime'</span> =&gt; <span style="color:#CC66CC;color:#800000;">20</span>, <span style="color:#FF0000;">'automaticSerialization'</span> =&gt; <span style="color:#000000; font-weight:bold;">true</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:#0000FF;">$backendOptions</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'cacheDir'</span> =&gt; <span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">framework</span>-&gt;<span style="color:#006600;">cache_dir</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;"><span style="color:#0000FF;">$dataCache</span> = Zend_Cache::<span style="color:#006600;">factory</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Core'</span>, <span style="color:#FF0000;">'File'</span>, <span style="color:#0000FF;">$frontendOptions</span>, <span style="color:#0000FF;">$backendOptions</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;">Zend::<span style="color:#006600;">register</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'dataCache'</span>, <span style="color:#0000FF;">$dataCache</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;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Wir setzen hier die automatische Serialisierung der Daten auf true, damit wir ohne größeren Aufwand auch Arrays speichern können. Die Lebenszeit können wir deutlich höher setzen als bei den Templates, da sich die zu cachenden Daten wie Kategorien meistens noch seltener ändern.</p>
<p>Danach ändere bitte in der Datei "Action.php" im Verzeichnis "/library/zf/Travello/Controller/" die Methode "getNavigation" wie folgt ab:</p>
<div class="igBar"><span id="lphp-60"><a href="#" onclick="javascript:showCodeTxt('php-60'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-60">
<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;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; private <span style="color:#000000; font-weight:bold;">function</span> getNavigation<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#0000FF;">$cacheId</span> = <span style="color:#FF0000;">'data_navigation'</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; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#0000FF;">$data</span> = Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'dataCache'</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$cacheId</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$category</span> = <span style="color:#000000; font-weight:bold;">new</span> CategoryModel<span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; &nbsp; &nbsp; </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:#0000FF;">$order</span>&nbsp; = <span style="color:#FF0000;">'cat_name'</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:#0000FF;">$rowset</span> = <span style="color:#0000FF;">$category</span>-&gt;<span style="color:#006600;">fetchAll</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">null</span>, <span style="color:#0000FF;">$order</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; &nbsp; &nbsp; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$data</span> = <span style="color:#0000FF;">$rowset</span>-&gt;<span style="color:#006600;">toArray</span><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'dataCache'</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">save</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$data</span>, <span style="color:#0000FF;">$cacheId</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; &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;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<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;">$data</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:#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;">&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;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<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>
<p></p>
<p>Wir legen wieder eine Cache Id fest und prüfen, ob es eine gültige Cache Datei gibt. Falls nicht, werden die Daten aus der Datenbank gelesen und im Cache gespeichert. Das war es auch schon. </p>
<p>Der Vollständigkeit halber hier die Änderungen für die Methode "getTagcloud":</p>
<div class="igBar"><span id="lphp-61"><a href="#" onclick="javascript:showCodeTxt('php-61'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-61">
<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;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; private <span style="color:#000000; font-weight:bold;">function</span> getTagcloud<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#0000FF;">$cacheId</span> = <span style="color:#FF0000;">'data_tagcloud'</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; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#0000FF;">$tags</span> = Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'dataCache'</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$cacheId</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$tag</span> = <span style="color:#000000; font-weight:bold;">new</span> TagModel<span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$db</span> = <span style="color:#0000FF;">$tag</span>-&gt;<span style="color:#006600;">getAdapter</span><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$select</span> = <span style="color:#0000FF;">$db</span>-&gt;<span style="color:#006600;">select</span><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$select</span>-&gt;<span style="color:#006600;">from</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'tag'</span>, <span style="color:#FF0000;">'tag.*, COUNT(tag_id) AS tag_count'</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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$select</span>-&gt;<span style="color:#006600;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art2tag'</span>, <span style="color:#FF0000;">'tag_id = art2tag_tag_id'</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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$select</span>-&gt;<span style="color:#006600;">order</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'tag_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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$select</span>-&gt;<span style="color:#006600;">group</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'tag_id'</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; &nbsp; &nbsp; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$tags</span> = <span style="color:#0000FF;">$db</span>-&gt;<span style="color:#006600;">fetchAll</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$select</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; &nbsp; &nbsp; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'dataCache'</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">save</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$tags</span>, <span style="color:#0000FF;">$cacheId</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; &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;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<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;">$tags</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:#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;">&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;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<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>
<p></p>
<p>Und hier die Änderungen für die Methode "getComments":</p>
<div class="igBar"><span id="lphp-62"><a href="#" onclick="javascript:showCodeTxt('php-62'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-62">
<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;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; private <span style="color:#000000; font-weight:bold;">function</span> getComments<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#0000FF;">$cacheId</span> = <span style="color:#FF0000;">'data_lastcomments'</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; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#0000FF;">$comments</span> = Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'dataCache'</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$cacheId</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$comment</span> = <span style="color:#000000; font-weight:bold;">new</span> CommentModel<span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$db</span> = <span style="color:#0000FF;">$comment</span>-&gt;<span style="color:#006600;">getAdapter</span><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$select</span> = <span style="color:#0000FF;">$db</span>-&gt;<span style="color:#006600;">select</span><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$select</span>-&gt;<span style="color:#006600;">from</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'comment'</span>, <span style="color:#FF0000;">'*'</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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$select</span>-&gt;<span style="color:#006600;">order</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'com_date DESC'</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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$select</span>-&gt;<span style="color:#006600;">limit</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC66CC;color:#800000;">5</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; &nbsp; &nbsp; &nbsp; &nbsp; </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:#0000FF;">$comments</span> = <span style="color:#0000FF;">$db</span>-&gt;<span style="color:#006600;">fetchAll</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$select</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; &nbsp; &nbsp; &nbsp; &nbsp; </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; Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'dataCache'</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">save</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$comments</span>, <span style="color:#0000FF;">$cacheId</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; &nbsp; &nbsp; <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;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#0000FF;">$comments</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;">&nbsp;</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;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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>
<p></p>
<p>Soviel erst einmal zur Zend_Cache Komponente, die auch noch viele weitere Anwendungsmöglichkeiten bietet. Zum Beispiel könnten wir unser Zend_Config Objekt auch in einer Cache Datei ablegen usw. </p>
<h3><a name="uebung">Übung: Caching für weitere Controller</a></h3>
<p>Als heutige Übung nehme dir bitte den TagController und den CategoryController vor und füge dort auch die Caching Funktionalität hinzu. Achte dabei auch darauf, dass du bei Änderungen alte Cache Dateien löscht. Zudem musst du natürlich auch die Anzeige der 404 Fehlerseite im IndexController cachen. Achte hier aber auf die Ausgabe des 404 Status, der immer ausgegeben werden muss. </p>
<p>Zur Kontrolle lade dir den aktuellen Stand des Tutorials runter. Dann kannst du deine Ergebnisse damit vergleichen.</p>
<h3><a name="download">Download</a></h3>
<p>Der aktuelle Stand des Tutorials nach diesem sechsten Teil kann herunter geladen werden. Hier sind auch alle Templates enthalten. Die Textdateien "empty.txt" in einigen Verzeichnissen habe ich nur angelegt, weil mein Winzip keine leeren Verzeichnisse im Zip Archiv anlegt:</p>
<ul>
<li><a href="http://www.ralfeggert.de/zfw/version-0.10.zip">http://www.ralfeggert.de/zfw/version-0.10.zip</a></li>
</ul>
<p>Die Zip Datei enthält nicht die aktuelle Version des Zend Frameworks. Dies musst du bitte selber in das entsprechende Verzeichnis kopieren. </p>
<h3><a name="zusammenfassung">Zusammenfassung</a></h3>
<p>In diesem zehnten Teil des Zend Framework Tutorials haben wir die Zend_Cache Komponente kennen gelernt und unsere erstellten Templates in Cache Dateien gespeichert. Wir haben uns außerdem darum gekümmert, dass Cache Dateien von Artikeln auch gelöscht werden, wenn es neue Kommentare gibt oder der Artikel geändert wird. Zudem haben wir einige Datenbankabfragen gecached, um die Datenbank zu entlasten.</p>
<p>Im nächsten Teil des Tutorials werde ich dir die nützlichen Komponenten Zend_Log für das Erstellen von individuellen Logs sowie Zend_Mail für den Versand von E-Mails vorstellen. </p>
<h3><a name="changelog">Change Log</a></h3>
<p>An dieser Stelle werden Änderungen an diesem Tutorial Teil zusammengefasst, die nach dem Ersterscheinen (23.10.2006) notwendig waren, z.B. durch neuere Versionen des Zend Frameworks oder Änderungen am Konzept des Tutorials oder den Anforderungen an unser TravelloBlog.</p>
<ul>
<li>05.11.2006: Tutorial für Release 0.2.0 aktualisiert</li>
</ul>
<h3><a name="navigation">Navigation</a></h3>
<ul>
<li><a href="http://www.ralfeggert.de/2006/10/16/zend-framework-tutorial-zend_filter_input/">Zurück zu Teil 9: Benutzereingaben filtern mit Zend_Filter_Input</a></li>
<li><a href="http://www.ralfeggert.de/2006/10/30/zend-framework-tutorial-zend_log-zend_mail/">Weiter zu Teil 11: Nützliche Komponenten Zend_Log und Zend_Mail</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ralfeggert.de/2006/10/24/zend-framework-tutorial-zend_cache/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Zend Framework Tutorial Teil 9: Benutzereingaben filtern mit Zend_Filter_Input</title>
		<link>http://www.ralfeggert.de/2006/10/16/zend-framework-tutorial-zend_filter_input/</link>
		<comments>http://www.ralfeggert.de/2006/10/16/zend-framework-tutorial-zend_filter_input/#comments</comments>
		<pubDate>Mon, 16 Oct 2006 06:17:34 +0000</pubDate>
		<dc:creator>Ralf Eggert</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.ralfeggert.de/2006/10/16/zend-framework-tutorial-zend_filter_input/</guid>
		<description><![CDATA[Im achten Teil vom Zend Framework Tutorial haben wir die Zend_Config Komponente für das Laden unsere Konfigurationsdaten verwendet, unsere Bootstrap Datei stark entschlackt und noch ganz nebenbei zwei Bugs aus dem siebten Teil bereinigt. Wenn du die ersten acht Teile noch nicht gelesen hast, hole dies bitte schnell nach.
In diesem neunten Teil des Tutorials widmen [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ralfeggert.de/2006/10/09/zend-framework-tutorial-zend-config/">Im achten Teil</a> vom <strong>Zend Framework Tutorial</strong> haben wir die Zend_Config Komponente für das Laden unsere Konfigurationsdaten verwendet, unsere Bootstrap Datei stark entschlackt und noch ganz nebenbei zwei Bugs aus dem siebten Teil bereinigt. Wenn du die ersten acht Teile noch nicht gelesen hast, <a href="http://www.ralfeggert.de/2006/08/26/einfuehrung-und-anforderungen/#aufbau">hole dies bitte schnell nach</a>.</p>
<p>In diesem neunten Teil des Tutorials widmen wir uns nun dem Filtern der Benutzereingaben mit der Zend Framework Komponente <strong>Zend_Filter_Input</strong>. Bisher haben wir direkt auf die Daten der globalen $_POST Variable zugegriffen, was zwar funktioniert, aber gewisse Sicherheitsprobleme bringen kann. Wir werden die Komponenten auch mit eigenen Methoden erweitern und uns in einer umfangreichen Übung um die Kommentarfunktion für unser TravelloBlog kümmern.</p>
<p>Wenn du über neue <strong>Tutorial</strong> Teile informiert werden möchtest, abonniere am besten den <a href="http://www.ralfeggert.de/feed/">Feed</a> dieses Blogs. Dann verpasst du garantiert keinen Teil des Tutorials.</p>
<p>Wichtig: Dieses Tutorial setzt die Zend Framework Preview Version 0.2.0 voraus und kann bei der Verwendung einer aktuelleren Version aus dem SVN unter Umständen nicht zu 100% funktionieren. </p>
<p><span id="more-68"></span></p>
<h3>Inhaltsverzeichnis</h3>
<ul>
<li><a href="#zend_filter">Zend_Filter</a></li>
<li><a href="#zend_filter_input">Zend_Filter_Input</a></li>
<li><a href="#objekt_erstellen">Zend_Filter_Input Objekt erstellen</a></li>
<li><a href="#articlecontroller">ArticleController ändern</a></li>
<li><a href="#erweitern">Zend_Filter und Zend_Filter_Input erweitern</a></li>
<li><a href="#weitere_controller">Weitere Controller ändern</a></li>
<li><a href="#uebung">Übung: Kommentarfunktion</a></li>
<li><a href="#download">Download</a></li>
<li><a href="#zusammenfassung">Zusammenfassung</a></li>
<li><a href="#changelog">Change log</a></li>
<li><a href="#navigation">Navigation</a></li>
<li><a href="#comments">Kommentare</a></li>
</ul>
<h3><a name="zend_filter">Zend_Filter</a></h3>
<p>Bevor wir uns Zend_Filter_Input widmen möchte ich zuerst die Komponente Zend_Filter vorstellen, da Zend_Filter_Input diese Komponente intensiv verwendet. Für eine erste sehr kurze Einführung empfehle ich wie immer den Blick ins <a href="http://framework.zend.com/manual/de/zend.filter.html">Zend_Filter Kapitel im Manual</a>. </p>
<div class="textbox">
<strong>Hinweis</strong></p>
<p>Das Kapitel im Manual über die Zend_Filter Komponente ist stark verbesserungswürdig und entspricht nicht mehr ganz dem aktuellen Stand der ZF 0.2.0 Version. So gibt es in Zend_Filter keine Methode testEmail(). Diese heißt isEmail().
</p></div>
<p>Zend_Filter ist im Prinzip eine Bibliothek mit statischen Methoden für das Filtern von Daten. Es stellt dabei drei Typen von Methoden bereit für unterschiedliche Anwendungsfälle beim Filtern von Daten. Hier wird zwischen dem so genannten Whitelist Filtern, dem Blinden Filtern und dem Blacklist Filtern unterschieden.</p>
<p>Beim Whitelist Filtern wird geprüft, ob die zu prüfenden Daten einem bestimmten Format entsprechen. Sind z.B. nicht erlaubte Zeichen enthalten oder entsprechen die Daten nicht dem Format wird "false" zurückgegeben. Andernfalls die korrekten Daten. Beim blinden Filtern werden nur die erwünschten Zeichen zurückgegeben. Und beim Blacklist Filtern wird geprüft, ob die Daten einem bestimmten Format entsprechen, um sie dann auszuschließen. </p>
<div class="textbox">
<strong>Hinweis</strong></p>
<p>Noch ein weiterer Hinweis. Die Methoden in Zend_Filter zum Blacklist Filtern sind im eigentlichen Sinne keine Blacklist Filter, sondern auch blinde Filter, weil sie Zeichen entfernen, die nicht in den zu prüfenden Daten vorkommen dürfen.
</p></div>
<p>Leider sind die Methoden im Manual noch nicht ausführlich dokumentiert. Um einen Überblick über die vorhandenen Methoden zu erhalten, empfehle ich entweder den direkten Blick in den Code von Zend_Filter und in die <a href="http://framework.zend.com/apidoc/core/">Api Docs</a>. Dort oben rechts das Paket Zend_Filter auswählen, dann rechts auf "Class trees" klicken und danach auf Zend_Filter klicken. Die Methoden, welche mit "get" beginnen, sind die blinden Filter und die Methoden, welche mit "is" beginnen, sind die Whitelist Filter.</p>
<h3><a name="zend_filter_input">Zend_Filter_Input</a></h3>
<p>Die Komponente Zend_Filter_Input setzt auf Zend_Filter auf und stellt einen guten Ansatz für das Filtern von Benutzereingaben bereit. Auch hier wieder der <a href="http://framework.zend.com/manual/de/zend.filter.input.html">Hinweis auf das Manual</a>, das ein wenig ausführlicher als das Kapitel zu Zend_Filter ist. </p>
<p>Um Zend_Filter_Input zu verwenden, wird eine Instanz erstellt und dabei ein Array mit Benutzereingaben übergeben. In der Regel handelt es sich dabei um die globale $_POST oder $_GET Variable. Hier ein einfaches Beispiel für die Anwendung:</p>
<div class="igBar"><span id="lphp-77"><a href="#" onclick="javascript:showCodeTxt('php-77'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-77">
<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;">&nbsp; &nbsp; <span style="color:#0000FF;">$filterPost</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Filter_Input<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$_POST</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; </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><span style="color:#0000FF;">$alphaName</span> = <span style="color:#0000FF;">$filterPost</span>-&gt;<span style="color:#006600;">testAlpha</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'name'</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:#008000;">/* $alphaName enthält nur Buchstaben. */</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> <span style="color:#616100;">else</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:#008000;">/* $alphaName evaluiert als FALSE. */</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:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Nach der Übergabe wird die $_POST bzw. $_GET Variable übrigens auf "null" gesetzt, so dass man fortan nur noch über das Zend_Filter_Input Objekt auf diese Daten zugreifen kann. Es bietet sich also an, ein Zend_Filter_Input Objekt im Objektspeicher abzulegen, so dass man von überall aus darauf zugreifen kann. Möchtest du das "auf null setzen" von $_POST bzw. $_GET vermeiden, musst du an den Konstruktor als zweiten Parameter "false" übergeben.</p>
<p>Leider sind die Methoden von Zend_Filter_Input im Manual ebenfalls noch nicht im Detail dokumentiert. Um einen Überblick über die vorhandenen Methoden zu erhalten, empfehle ich entweder den direkten Blick in den Code von Zend_Filter_Input und in die <a href="http://framework.zend.com/apidoc/core/">Api Docs</a>. Dort oben rechts das Paket Zend_Filter auswählen, dann rechts auf "Class trees" klicken und danach auf Zend_Filter_Input klicken. Die Methoden, welche mit "get" beginnen, sind die blinden Filter und die Methoden, welche mit "test" beginnen, sind die Whitelist Filter.</p>
<h3><a name="objekt_erstellen">Zend_Filter_Input Objekt erstellen</a></h3>
<p>Um ein Zend_Filter_Input Objekt verwenden zu können, müssen wir es erst erstellen und dann im Objektspeicher ablegen, damit wir uns unseren Controller Klassen auf die Daten zugreifen können. Öffne also nun die Datei "settings.php" im Verzeichnis "/application/config" und füge ans Ende folgende Zeilen ein:</p>
<div class="igBar"><span id="lphp-78"><a href="#" onclick="javascript:showCodeTxt('php-78'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-78">
<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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$post</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Filter_Input<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$_POST</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;">Zend::<span style="color:#006600;">register</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'post'</span>, <span style="color:#0000FF;">$post</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;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Für unser TravelloBlog brauchen wir vorerst nur ein Filter Objekt für die $_POST Daten. Du kannst aber auf die gleiche Weise auch ein Filter Objekt für die $_GET Daten anlegen.</p>
<p>Das war es auch schon und wir können uns direkt ums Filtern der Eingabedaten in unseren Controller Klassen kümmern.</p>
<h3><a name="articlecontroller">ArticleController ändern</a></h3>
<p>Bisher greifen wir im ArticleController nur in den Methoden validateAction und doDeleteAction auf die $_POST Variable zu. Also müssen wir diese Methoden überarbeiten. </p>
<p>Öffne nun die Datei "ArticleController.php" im Verzeichnis "/application/controllers/" und suche nach der validateAction Methode. Ändere nun die ersten Zeilen wie folgt ab:</p>
<div class="igBar"><span id="lphp-79"><a href="#" onclick="javascript:showCodeTxt('php-79'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-79">
<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;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> validateAction<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#0000FF;">$post</span> = Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'post'</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">keyExists</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'button_save'</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$url</span> = getRewriteBase<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> . <span style="color:#FF0000;">'/'</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; </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:#0000FF;">$this</span>-&gt;_redirect<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$url</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; &nbsp; &nbsp; <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;">&nbsp; &nbsp; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<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>
<p></p>
<p>Als erstes holen wir uns das Zend_Filter_Objekt zurück aus dem Objektspeicher. Dann prüfen wir, ob der Schlüssel "button_save" vorhanden ist, d.h. ob der Speicherbutton angeklickt worden ist. Falls der Schlüssel nicht vorhanden ist, leiten wir auf die Startseite unseres TravelloBlogs um, um direkte Aufrufe der validateAction Methode zu verhindern.</p>
<p>Als nächstes passen wir den Codeblock an, in dem die übertragenen Daten an unser $data Array übergeben werden, damit diese später gespeichert werden können. Ändere also die folgenden Zeilen  wie folgt ab:</p>
<div class="igBar"><span id="lphp-80"><a href="#" onclick="javascript:showCodeTxt('php-80'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-80">
<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;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> validateAction<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$data</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">keyExists</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art_id'</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">getDigits</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art_id'</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; &nbsp; &nbsp; <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;">&nbsp; &nbsp; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art_title'</span> <span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">getRaw</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art_title'</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; &nbsp; &nbsp; <span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art_teaser'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">getRaw</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art_teaser'</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; &nbsp; &nbsp; <span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art_text'</span>&nbsp; <span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">getRaw</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art_text'</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; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art2cat_cat_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">keyExists</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art2cat_cat_id'</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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ? <span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">getDigits</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art2cat_cat_id'</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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color:#000000; font-weight:bold;">null</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; </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:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art2tag_tag_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">keyExists</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art2tag_tag_id'</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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ? <span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">getDigits</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art2tag_tag_id'</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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color:#000000; font-weight:bold;">null</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; </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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<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>
<p></p>
<p>Hier prüfen wir zuerst, ob ein Wert für "art_id" übergeben worden ist, und falls ja, werden alle Zeichen, die keine Ziffern sind, gefiltert. Das heißt also, dass ein Aufruf von Zend_Filter_Input::getDigits() nur Ziffern zurück liefert.</p>
<p>Für die Felder "art_title", "art_teaser" und "art_text" lassen wir uns erst einmal die rohen Daten zurück geben, da wir diese gleich noch detaillierter testen möchten. Für die beiden Felder "art2cat_cat_id" und "art2tag_tag_id" verwenden wir wieder Zend_Filter_Input::getDigits() und sehen, dass die Funktion sogar auf Arrays angewendet werden kann.</p>
<p>Jetzt wird in validateAction schon mal nicht mehr direkt auf die $_POST Variable zugegriffen. Wir können aber die Daten noch weiter prüfen und gegen nicht erwünschte Eingaben prüfen. Dafür ändern wir den nächsten Codeabschnitt nun wie folgt:</p>
<div class="igBar"><span id="lphp-81"><a href="#" onclick="javascript:showCodeTxt('php-81'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-81">
<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;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> validateAction<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$errors</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/strlen"><span style="color:#000066;">strlen</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art_title'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> == <span style="color:#CC66CC;color:#800000;">0</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$errors</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art_title'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">'Please enter a title!'</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:#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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">elseif</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">testRegex</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art_title'</span>, <span style="color:#FF0000;">'=[^[:alnum:]<span style="color:#000099; font-weight:bold;">\ </span><span style="color:#000099; font-weight:bold;">\-</span><span style="color:#000099; font-weight:bold;">\.</span><span style="color:#000099; font-weight:bold;">\,</span><span style="color:#000099; font-weight:bold;">\!</span><span style="color:#000099; font-weight:bold;">\?</span><span style="color:#000099; font-weight:bold;">\/</span>]='</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$errors</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art_title'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">'Only letters, digits, spaces and the following signs allowed: -/.,!?'</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:#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;">&nbsp; &nbsp; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">testRegex</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art_teaser'</span>, <span style="color:#FF0000;">'=[^[:alnum:]<span style="color:#000099; font-weight:bold;">\ </span><span style="color:#000099; font-weight:bold;">\-</span><span style="color:#000099; font-weight:bold;">\.</span><span style="color:#000099; font-weight:bold;">\,</span><span style="color:#000099; font-weight:bold;">\!</span><span style="color:#000099; font-weight:bold;">\?</span><span style="color:#000099; font-weight:bold;">\/</span>]='</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; <span style="color:#0000FF;">$errors</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art_teaser'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">'Only letters, digits, spaces and the following signs allowed: -/.,!?'</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; <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;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/strlen"><span style="color:#000066;">strlen</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art_text'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> == <span style="color:#CC66CC;color:#800000;">0</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$errors</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art_text'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">'Please enter a text!'</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:#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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">elseif</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art_text'</span><span style="color:#006600; font-weight:bold;">&#93;</span> != <span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">noTags</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art_text'</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$errors</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art_text'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">'No tags allowed!'</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:#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;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<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>
<p></p>
<p>Für die beiden Felder "art_title" und "art_teaser" führen wir nun eine weitere Prüfung mit Hilfe eines regulären Ausdrucks ein, der auf Buchstaben, Ziffern, Leerzeichen und ausgewählte Satzzeichen prüft. Für das Feld "art_text" prüfen wir zudem, ob HTML Tags im Text vorhanden sind und geben dann eine entsprechende Fehlermeldung aus. </p>
<p>Rufe nun einmal in deinem Browser das TravelloBlog auf und ändere einen Artikel. Gebe dort bewusst Daten ein, welche die Fehlermeldungen hervorrufen sollen und klicke dann auf Speichern. Dies könnte dann in etwa wie folgt aussehen:</p>
<p><img id="image69" src="http://www.ralfeggert.de/wp-content/uploads/2006/10/9-screen1.png" alt="Artikel validieren" /></p>
<p>Das funktioniert also schon einmal sehr gut. Eine Sache ist aber noch ein wenig störend. Wenn wir unseren regulären Ausdruck zum Prüfen von "art_title" und "art_teaser" ändern möchte, um z.B. ein weiteres Zeichen zu den erlaubten hinzuzufügen, müssen wir das schon an zwei Stellen ändern. Verwenden wir den regulären Ausdruck auch in anderen Controllern wird es schnell unübersichtlich. </p>
<p>Du fragst dich nun also sicher, ob du nicht auch Zend_Filter_Input anpassen kannst, um den regulären Ausdruck dort zentral für Prüfungen ablegen zu können. Kannst du, also lies schnell weiter!</p>
<h3><a name="erweitern">Zend_Filter und Zend_Filter_Input erweitern</a></h3>
<p>Um unseren regulären Ausdruck nicht nur in Zend_Filter_Input, sondern auch bei der direkten Verwendung von Zend_Filter verwenden zu können, müssen wir beide Klassen erweitern. </p>
<p>Wir beginnen mit Zend_Filter und erstellen nun im Verzeichnis "/library/zf/Travello" die Datei "Filter.php" mit folgendem Code:</p>
<div class="igBar"><span id="lphp-82"><a href="#" onclick="javascript:showCodeTxt('php-82'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-82">
<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:#000000; font-weight:bold;">class</span> Travello_Filter extends Zend_Filter</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;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; public <a href="http://www.php.net/static"><span style="color:#000066;">static</span></a> <span style="color:#000000; font-weight:bold;">function</span> isTitle<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$value</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:#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; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#006600; font-weight:bold;">&#40;</span>bool<span style="color:#006600; font-weight:bold;">&#41;</span> <a href="http://www.php.net/preg_match"><span style="color:#000066;">preg_match</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'=[^[:alnum:]<span style="color:#000099; font-weight:bold;">\ </span><span style="color:#000099; font-weight:bold;">\-</span><span style="color:#000099; font-weight:bold;">\.</span><span style="color:#000099; font-weight:bold;">\,</span><span style="color:#000099; font-weight:bold;">\!</span><span style="color:#000099; font-weight:bold;">\?</span><span style="color:#000099; font-weight:bold;">\/</span>]='</span>, <span style="color:#0000FF;">$value</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:#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;">&nbsp; &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:#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;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Das war es schon? Ja, das war es schon. Der Name ist vielleicht nicht ganz glücklich gewählt, aber mir ist an dieser Stelle nichts besseres eingefallen. Um diese Methoden nun auch mit unserer Zend_Filter_Input Instanz verwenden zu können, müssen wir auch diese Klasse erweitern.</p>
<p>Erstelle nun also das Verzeichnis "/library/zf/Travello/Filter" und lege dort die Datei "Input.php" mit folgendem Code an:</p>
<div class="igBar"><span id="lphp-83"><a href="#" onclick="javascript:showCodeTxt('php-83'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-83">
<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:#000000; font-weight:bold;">class</span> Travello_Filter_Input extends Zend_Filter_Input</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;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> testTitle<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$key</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:#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; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">keyExists</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$key</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; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">false</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; <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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>Travello_Filter::<span style="color:#006600;">isTitle</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;_source<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF;">$key</span><span style="color:#006600; font-weight:bold;">&#93;</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-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#0000FF;">$this</span>-&gt;_source<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF;">$key</span><span style="color:#006600; font-weight:bold;">&#93;</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:#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;">&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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">FALSE</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>
<li style="font-weight: bold;color:#26536A;">
<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>
<p></p>
<p>In der Methode Travello_Filter_Input::testTitle() wird zuerst geprüft, ob ein Wert für den Schlüssel vorhanden ist. Danach wird die Travello_Filter::isTitle() Methode aufgerufen und bei erfolgreicher Prüfung der Wert zurückgegeben.</p>
<p>Um unsere erweiterten Klassen verwenden zu können, müssen wir nun die Instantiierung in der "settings.php" Datei entsprechend anpassen:</p>
<div class="igBar"><span id="lphp-84"><a href="#" onclick="javascript:showCodeTxt('php-84'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-84">
<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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$post</span> = <span style="color:#000000; font-weight:bold;">new</span> Travello_Filter_Input<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$_POST</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;">Zend::<span style="color:#006600;">register</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'post'</span>, <span style="color:#0000FF;">$post</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;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Und zum Schluss passen wir nun noch die validateAction Methode in unserem ArticleController an, indem wir den Aufruf von testRegex() durch testTitle() ersetzen:</p>
<div class="igBar"><span id="lphp-85"><a href="#" onclick="javascript:showCodeTxt('php-85'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-85">
<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;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> validateAction<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">elseif</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">testTitle</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art_title'</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$errors</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art_title'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">'Only letters, digits, spaces and the following signs allowed: -/.,!?'</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:#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;">&nbsp; &nbsp; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">testTitle</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art_teaser'</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; <span style="color:#0000FF;">$errors</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art_teaser'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">'Only letters, digits, spaces and the following signs allowed: -/.,!?'</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; <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;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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>
<p></p>
<p>Prüfe das Ganze nun noch einmal in deinem Browser und es sollte weiterhin wie gewünscht funktionieren. Du kannst natürlich Travello_Filter und Travello_Filter_Input auch um weitere Methoden für zusätzliche Filter ergänzen. </p>
<p>Da die Methode Zend_Filter::isEmail() derzeit noch nicht implementiert ist, übernehmen wir das nun, da wir eine Prüfung auf eine E-Mail Adresse später noch brauchen werden. Füge also in Travello_Filter nun noch folgende zweite Methode hinzu:</p>
<div class="igBar"><span id="lphp-86"><a href="#" onclick="javascript:showCodeTxt('php-86'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-86">
<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:#000000; font-weight:bold;">class</span> Travello_Filter extends Zend_Filter</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;">&#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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; public <a href="http://www.php.net/static"><span style="color:#000066;">static</span></a> <span style="color:#000000; font-weight:bold;">function</span> isEmail<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$value</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:#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; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#006600; font-weight:bold;">&#40;</span>bool<span style="color:#006600; font-weight:bold;">&#41;</span> <a href="http://www.php.net/preg_match"><span style="color:#000066;">preg_match</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'=^[a-z0-9][<span style="color:#000099; font-weight:bold;">\.</span>_a-z0-9-]*@[a-z0-9][<span style="color:#000099; font-weight:bold;">\.</span>a-z0-9-]*(<span style="color:#000099; font-weight:bold;">\.</span>[a-z]{2,6})$=i'</span>, <span style="color:#0000FF;">$value</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:#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;"><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:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Dies ist natürlich keine, auch nur annähernd perfekte Prüfung auf eine gültige E-Mail Adresse, aber für unsere Zwecke reicht es. Wer Langeweile hat kann gerne <a href="http://www.ietf.org/rfc/rfc2822.txt">RFC 2822</a> komplett implementieren und den Code dann der Zend Framework Community zur Verfügung stellen. </p>
<p>In Travello_Filter_Input musst du nun noch den Aufruf unser eigenen isEmail Methode einfügen:</p>
<div class="igBar"><span id="lphp-87"><a href="#" onclick="javascript:showCodeTxt('php-87'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-87">
<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:#000000; font-weight:bold;">class</span> Travello_Filter_Input extends Zend_Filter_Input</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;">&#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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> testEmail<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$key</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:#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; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">keyExists</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$key</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; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">false</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; <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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>Travello_Filter::<span style="color:#006600;">isEmail</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;_source<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF;">$key</span><span style="color:#006600; font-weight:bold;">&#93;</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-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#0000FF;">$this</span>-&gt;_source<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF;">$key</span><span style="color:#006600; font-weight:bold;">&#93;</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:#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;">&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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">FALSE</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:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h3><a name="weitere_controller">Weitere Controller ändern</a></h3>
<p>Bevor wir uns TagController und CategoryController widmen, müssen wir noch die Abfrage in doDeleteAction wie bei validateAction entsprechen anpassen:</p>
<div class="igBar"><span id="lphp-88"><a href="#" onclick="javascript:showCodeTxt('php-88'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-88">
<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;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> doDeleteAction<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#0000FF;">$post</span> = Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'post'</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">keyExists</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'button_delete'</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$url</span> = getRewriteBase<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> . <span style="color:#FF0000;">'/'</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; </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:#0000FF;">$this</span>-&gt;_redirect<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$url</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; &nbsp; &nbsp; <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;">&nbsp; &nbsp; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<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>
<p></p>
<p>Auf die gleiche Weise kannst du auch die Methoden doDeleteAction im TagController und im CategoryController anpassen.</p>
<p>Für Tags möchten wir nur Buchstaben, das Leerzeichen und das kaufmännische Und zulassen. Du kannst für diese Prüfung gerne auch eine eigene Methode in Travello_Filter einführen. Die Methode validateAction im TagController ändere also wie folgt ab:</p>
<div class="igBar"><span id="lphp-89"><a href="#" onclick="javascript:showCodeTxt('php-89'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-89">
<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;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> validateAction<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#0000FF;">$post</span> = Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'post'</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">keyExists</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'button_save'</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$url</span> = getRewriteBase<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> . <span style="color:#FF0000;">'/tag/'</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; </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:#0000FF;">$this</span>-&gt;_redirect<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$url</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; &nbsp; &nbsp; <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;">&nbsp; &nbsp; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$data</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">keyExists</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'tag_id'</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; <span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'tag_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">getDigits</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'tag_id'</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; &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;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'tag_name'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">getRaw</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'tag_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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$errors</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/strlen"><span style="color:#000066;">strlen</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'tag_name'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> == <span style="color:#CC66CC;color:#800000;">0</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$errors</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'tag_name'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">'Please enter a name for the tag!'</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:#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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">elseif</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">testRegex</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'tag_name'</span>, <span style="color:#FF0000;">'=[^[:alpha:]<span style="color:#000099; font-weight:bold;">\ </span><span style="color:#000099; font-weight:bold;">\&#038;</span>]='</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$errors</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'tag_name'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">'Only letters, spaces and ampersand allowed'</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:#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;">&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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<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>
<p></p>
<p>Für Kategorien möchten wir nur Buchstaben, Ziffern, den Bindestrich und das Leerzeichen zulassen. Du kannst für diese Prüfung gerne auch eine eigene Methode in Travello_Filter einführen. Die Methode validateAction im CategoryController ändere also wie folgt ab:</p>
<div class="igBar"><span id="lphp-90"><a href="#" onclick="javascript:showCodeTxt('php-90'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-90">
<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;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> validateAction<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#0000FF;">$post</span> = Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'post'</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">keyExists</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'button_save'</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$url</span> = getRewriteBase<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> . <span style="color:#FF0000;">'/category/'</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; </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:#0000FF;">$this</span>-&gt;_redirect<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$url</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; &nbsp; &nbsp; <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;">&nbsp; &nbsp; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$data</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">keyExists</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'cat_id'</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; <span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'cat_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">getDigits</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'cat_id'</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; &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;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'cat_name'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">getRaw</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'cat_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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$errors</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/strlen"><span style="color:#000066;">strlen</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'cat_name'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> == <span style="color:#CC66CC;color:#800000;">0</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$errors</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'cat_name'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">'Please enter a name for the category!'</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:#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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">elseif</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$post</span>-&gt;<span style="color:#006600;">testRegex</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'cat_name'</span>, <span style="color:#FF0000;">'=[^[:alnum:]<span style="color:#000099; font-weight:bold;">\ </span><span style="color:#000099; font-weight:bold;">\-</span>]='</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; &nbsp; &nbsp; <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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$errors</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'cat_name'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">'Only letters, digits, spaces and hyphens allowed'</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:#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;">&nbsp; &nbsp; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<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>
<p></p>
<h3><a name="uebung">Übung: Kommentarfunktion</a></h3>
<p>Die heutige Übung ist etwas umfangreicher als sonst und hat nicht ausschließlich etwas mit den heute vorgestellten Komponente Zend_Filter_Input zu tun. Auch wenn du dabei natürlich Zend_Filter_Input bzw. unsere erweiterte Klasse verwenden sollst.</p>
<p>Bitte implementiere nun die Kommentarfunktion für Artikel und setze dabei diese Punkte um:</p>
<ul>
<li>Ausgabe aller vorhandenen Kommentare bei einem Artikel (ältester oben)</li>
<li>Hinzufügen von neuen Kommentaren zu einem Artikel</li>
<li>Ändern und Löschen bestehender Kommentare</li>
<li>Ausgabe der ersten 40 Zeichen der 5 letzten Kommentaren in der Box 2 auf der rechten Seite (neuester oben)</li>
</ul>
<p>Diese Übung ist wie gesagt deutlich umfangreicher als die bisherigen Übungen. Da wir aber im letzten Teil sowieso keine Übung dabei hatten und mit dieser Übung noch einmal alles bisher Gelernte angewandt werden muss, ist diese Übung sehr sinnvoll. </p>
<p>Damit du nicht vollkommen verloren bist, hier ein paar Tipps, wie du die Sache angehen könntest:</p>
<ul>
<li>Als erstes brauchst du natürlich eine neue Model Klasse für Kommentare sowie Templates für Kommentare zur Darstellung eines Formulars.</li>
<li>Als nächstes musst du den CommentController mit den Methoden buildForm, saveData, changeAction, validateAction, deleteAction und doDeleteAction ausstatten. </li>
<li>Dann benötigst du noch zwei Templates: eines zum Anzeigen des Kommentarformulars und eines zum Löschen eines Kommentars.</li>
<li>Nach dem Anlegen, Ändern und Löschen eines Kommentars solltest du per Redirect auf den entsprechenden Artikel umleiten, zu dem der Kommentar gehört.</li>
<li>Die Anzeige der letzten Kommentare in der Box 2 lässt sich ähnlich wie die Tagwolke erledigen.</li>
<li>Zusätzlich könntest du noch ein wenig Hand an unsere CSS Datei anlegen, damit die Ausgabe der Kommentare etwas besser aussieht.</li>
<li>Und nicht vergessen die Methode ArticleController::doDeleteAction so anzupassen, dass beim Löschen eines Artikels auch die zugehörigen Kommentare gelöscht werden.</li>
</ul>
<p>Zur Kontrolle lade dir den aktuellen Stand des Tutorials runter. Dann kannst du deine Ergebnisse damit vergleichen.</p>
<h3><a name="download">Download</a></h3>
<p>Der aktuelle Stand des Tutorials nach diesem sechsten Teil kann herunter geladen werden. Hier sind auch alle Templates enthalten. Die Textdateien "empty.txt" in einigen Verzeichnissen habe ich nur angelegt, weil mein Winzip keine leeren Verzeichnisse im Zip Archiv anlegt:</p>
<ul>
<li><a href="http://www.ralfeggert.de/zfw/version-0.9.zip">http://www.ralfeggert.de/zfw/version-0.9.zip</a></li>
</ul>
<p>Die Zip Datei enthält nicht die aktuelle Version des Zend Frameworks. Dies musst du bitte selber in das entsprechende Verzeichnis kopieren. </p>
<h3><a name="zusammenfassung">Zusammenfassung</a></h3>
<p>In diesem neunten Teil des Zend Framework Tutorials haben wir die Zend_Filter und Zend_Filter_Input Komponenten kennen gelernt und für die Prüfung der Eingabedaten durch die Nutzer verwendet. Wir haben die beiden Klassen auch um eigene Funktionen erweitert, so dass wir fortan an ein gutes, zentrales Werkzeug für das Filtern von Benutzereingaben haben.</p>
<p>Im nächsten Teil des Tutorials werden wir uns dem Cachen von diversen Daten kümmern und die <strong>Zend_Cache</strong> Komponente kennen lernen. </p>
<h3><a name="changelog">Change Log</a></h3>
<p>An dieser Stelle werden Änderungen an diesem Tutorial Teil zusammengefasst, die nach dem Ersterscheinen (16.10.2006) notwendig waren, z.B. durch neuere Versionen des Zend Frameworks oder Änderungen am Konzept des Tutorials oder den Anforderungen an unser TravelloBlog.</p>
<ul>
<li>05.11.2006: Tutorial für Release 0.2.0 aktualisiert</li>
</ul>
<h3><a name="navigation">Navigation</a></h3>
<ul>
<li><a href="http://www.ralfeggert.de/2006/10/09/zend-framework-tutorial-zend-config/">Zurück zu Teil 8: Konfiguration mit Zend_Config</a></li>
<li><a href="http://www.ralfeggert.de/2006/10/24/zend-framework-tutorial-zend_cache/">Weiter zu Teil 10: Sinnvoll cachen mit Zend_Cache</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ralfeggert.de/2006/10/16/zend-framework-tutorial-zend_filter_input/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Zend Framework Tutorial Teil 8: Konfiguration mit Zend_Config</title>
		<link>http://www.ralfeggert.de/2006/10/09/zend-framework-tutorial-zend-config/</link>
		<comments>http://www.ralfeggert.de/2006/10/09/zend-framework-tutorial-zend-config/#comments</comments>
		<pubDate>Mon, 09 Oct 2006 05:23:31 +0000</pubDate>
		<dc:creator>Ralf Eggert</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.ralfeggert.de/2006/10/09/zend-framework-tutorial-zend-config/</guid>
		<description><![CDATA[Im siebten Teil vom Zend Framework Tutorial haben wir uns ein wenig intensiver mit Zend_Controller, Zend_Db und Zend_View auseinander gesetzt und unsere Anwendung navigierbarer und mit Hilfe von CSS auch ein wenige hübscher gemacht. Wenn du die ersten sieben Teile noch nicht gelesen hast, hole dies bitte schnell nach.
In diesem achten Teil des Tutorials widmen [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ralfeggert.de/2006/10/02/zend-framework-tutorial-mvc-controller/">Im siebten Teil</a> vom Zend Framework Tutorial haben wir uns ein wenig intensiver mit Zend_Controller, Zend_Db und Zend_View auseinander gesetzt und unsere Anwendung navigierbarer und mit Hilfe von CSS auch ein wenige hübscher gemacht. Wenn du die ersten sieben Teile noch nicht gelesen hast, <a href="http://www.ralfeggert.de/2006/08/26/einfuehrung-und-anforderungen/#aufbau">hole dies bitte schnell nach</a>.</p>
<p>In diesem achten Teil des Tutorials widmen wir uns nun einer neuen Komponente. An mehreren Stellen in unserer Applikation haben wir bereits verschiedene Konfigurationsdaten eingeführt. Es macht jedoch sehr viel Sinn, alle Konfigurationsdaten an einer zentralen Stelle abzulegen und von überall aus zugreifbar zu machen. Dabei hilft uns die Komponente Zend_Config. Außerdem werden wir unsere Applikation auch heute noch ein wenig mehr aufräumen und zwei Bugs fixen. </p>
<p>Wenn du über neue <strong>Tutorial</strong> Teile informiert werden möchtest, abonniere am besten den <a href="http://www.ralfeggert.de/feed/">Feed</a> dieses Blogs. Dann verpasst du garantiert keinen Teil des Tutorials.</p>
<p>Wichtig: Dieses Tutorial setzt die Zend Framework Preview Version 0.2.0 voraus und kann bei der Verwendung einer aktuelleren Version aus dem SVN unter Umständen nicht zu 100% funktionieren. </p>
<p><span id="more-63"></span></p>
<h3>Inhaltsverzeichnis</h3>
<ul>
<li><a href="#zend_config">Zend_Config</a></li>
<li><a href="#ini-datei">Eine .ini Konfigurationsdatei erstellen</a></li>
<li><a href="#settings-anlegen">Datei settings.php anlegen</a></li>
<li><a href="#bootstrap">Bootstrap Datei entschlacken</a></li>
<li><a href="#gesamte-settings">Die gesamte settings.php Datei</a></li>
<li><a href="#aufraeumarbeiten">Aufräumarbeiten</a></li>
<li><a href="#fehlerseite">Zentrale 404 Fehlerseite einrichten</a></li>
<li><a href="#bugfixing">Bugfixing</a></li>
<li><a href="#articlecontroller">ArticleController überarbeiten</a></li>
<li><a href="#download">Download</a></li>
<li><a href="#zusammenfassung">Zusammenfassung</a></li>
<li><a href="#changelog">Change log</a></li>
<li><a href="#navigation">Navigation</a></li>
<li><a href="#comments">Kommentare</a></li>
</ul>
<h3><a name="zend_config">Zend_Config</a></h3>
<p>Als Einführung in die Zend_Config Komponente empfehle ich dir, erst einmal einen kurzen Blick in das <a href="http://framework.zend.com/manual/de/zend.config.html">Zend_Config Kapitel im Manual</a> zu werfen. Dort erfährst du schon ein wenig über die Funktionsweise von Zend_Config.</p>
<p>Für das Einlesen der Konfigurationsdaten stellt Zend_Config mehrere Ladeklassen bereit. So können die Daten aus einem PHP Array, einer .ini Datei oder einer XML Datei gelesen und in einem Zend_Config Objekt für die Anwendung bereit gestellt werden. </p>
<p>Es kann sogar auf so genannte "Sections" zugegriffen werden, um bestimmte Bereiche einer Konfigurationsdatei zu laden. Dadurch können z.B. die Zugriffsdaten für eine Datenbank für die Entwicklung und die Produktion in der selben Datei vorgehalten werden.</p>
<p>Eine beispielhafte .ini Konfigurationsdatei könnte wie folgt aussehen:</p>
<div class="codebox">
<pre>
[production]
base_url  = /my/base/url

database.type     = pdo_mysql
database.host     = db.example.com
database.username = dbuser
database.password = secret
database.name     = dbname
colours.website.green = 00FF00
colours.website.blue  = 0000FF

colours.navi.green = 00CC00
colours.navi.blue  = 0000CC

[development : production]
database.host     = db-dev.example.com
</pre>
</div>
<p>Das Laden sähe dann wie folgt aus:</p>
<div class="igBar"><span id="lphp-110"><a href="#" onclick="javascript:showCodeTxt('php-110'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-110">
<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> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Config_Ini<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'/path/to/config.ini'</span>, <span style="color:#FF0000;">'production'</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Nach dem Laden der Konfigurationsdaten kann dann sehr einfach auf selbige zugegriffen werden. Dabei sind auch beliebig tiefe Verschachtelungen möglich, wie diese Beispiele zeigen. Außerdem steht die Methode asArray() bereit, um ein Array zurückzugeben:</p>
<div class="igBar"><span id="lphp-111"><a href="#" onclick="javascript:showCodeTxt('php-111'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-111">
<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;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">base_url</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;">$config</span>-&gt;<span style="color:#006600;">database</span>-&gt;<span style="color:#006600;">host</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;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">colours</span>-&gt;<span style="color:#006600;">website</span>-&gt;<span style="color:#006600;">green</span>;</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:#0000FF;">$database</span> = <span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">database</span>-&gt;<span style="color:#006600;">asArray</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Für detailliertere Informationen zu Zend_Config möchte ich nochmals auf das <a href="http://framework.zend.com/manual/de/zend.config.html">Manual</a> hinweisen.</p>
<h3><a name="ini-datei">Eine .ini Konfigurationsdatei erstellen</a></h3>
<p>Als erstes müssen wir einmal schauen, welche Daten sich dazu anbieten, dass sie zentral in einer Konfigurationsdatei abgelegt werden. Primär sind diese Daten bisher in unserer Bootstrap Datei enthalten. Es bieten sich vor allem die verschiedenen Verzeichnispfade, die Datenbankparameter und die Routen an.</p>
<p>Lege also nun im Verzeichnis "/application/config" die Datei "settings.ini" mit folgendem Inhalt an:</p>
<div class="codebox">
<pre>
[production]
# Settings for the Zend Framework
framework.application_dir = /path/to/travelloblog/application
framework.controller_dir  = /path/to/travelloblog/application/controllers
framework.model_dir       = /path/to/travelloblog/application/models
framework.view_dir        = /path/to/travelloblog/application/views
framework.view_helper_dir = /path/to/travelloblog/library/zf/Travello/View\Helper

# Settings for the database
database.adapter = PDO_MYSQL
database.params.host     = my.host.de
database.params.username = secret
database.params.password = muchmorsecret
database.params.dbname   = travelloblog

[development : production]
# Settings for the Zend Framework
framework.application_dir = e:\travelloblog\application
framework.controller_dir  = e:\travelloblog\application\controllers
framework.model_dir       = e:\travelloblog\application\models
framework.view_dir        = e:\travelloblog\application\views
framework.view_helper_dir = e:\travelloblog\library\zf\Travello\View\Helper

# Settings for the database
database.adapter = PDO_MYSQL
database.params.host     = 127.0.0.1
database.params.username = root
database.params.password =
database.params.dbname   = travelloblog
</pre>
</div>
<p>In dieser Datei habe ich sowohl die Daten für unseren Entwicklungsrechner als auch für den Produktionsserver abgelegt.</p>
<p>Übrigens brauchst du dir keine Sorgen machen, dass jemand fälschlicherweise diese .ini Datei direkt über den Browser anzeigen lassen kann. Dies haben wir durch unsere ".htaccess" Datei im Verzeichnis "/application" bereits ausgeschlossen.</p>
<h3><a name="settings-anlegen">Datei settings.php anlegen</a></h3>
<p>Natürlich können wir die Konfigurationsdaten auch direkt in unserer Bootstrap Datei laden. Ich habe mir jedoch angewöhnt, das Laden von Konfigurationsdaten in eine eigene Datei auszulagern. Das macht die Bootstrap Datei übersichtlicher und eventuelle Sicherheitsprobleme beim fehlerhaften Ausliefern der Bootstrap Datei werden auch umgangen.</p>
<p>Lege also nun im Verzeichnis "/application/config" die Datei "settings.php" mit folgendem Inhalt an:</p>
<div class="igBar"><span id="lphp-112"><a href="#" onclick="javascript:showCodeTxt('php-112'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-112">
<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:#0000FF;">$iniFile</span> = <a href="http://www.php.net/dirname"><span style="color:#000066;">dirname</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> . DIRECTORY_SEPARATOR . <span style="color:#FF0000;">'settings.ini'</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:#0000FF;">$config</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Config_Ini<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$iniFile</span>, <span style="color:#FF0000;">'development'</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;">Zend::<span style="color:#006600;">register</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'config'</span>, <span style="color:#0000FF;">$config</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Zend::<span style="color:#006600;">dump</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">asArray</span><span style="color:#006600; font-weight:bold;">&#40;</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:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Wir laden also die Daten aus der Konfigurationsdatei "settings.ini" und legen das Zend_Config Objekt im Objektspeicher ab. Danach geben wir zum Testen einmal alle Daten aus.</p>
<p>Da du diese Datei nicht direkt über den Browser aufrufen kannst, müssen wir sie nun noch in unserer Bootstrap Datei einbinden. Öffnen also die Datei "index.php" im Verzeichnis "/public" und ändere sie wie folgt:</p>
<div class="igBar"><span id="lphp-113"><a href="#" onclick="javascript:showCodeTxt('php-113'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-113">
<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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">require_once</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'set_include_path.php'</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">require_once</span> <span style="color:#FF0000;">'Zend.php'</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">require_once</span> <span style="color:#FF0000;">'settings.php'</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> __autoload<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$class</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;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; Zend::<span style="color:#006600;">loadClass</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$class</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;">&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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<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>
<p></p>
<p>Wenn du nun das TravelloBlog im Browser aufrufst, sollte oben folgende Ausgabe erscheinen:</p>
<div class="codebox">
<pre>
array(2) {
  ["framework"] => array(5) {
    ["application_dir"] => string(27) "e:\travelloblog\application"
    ["controller_dir"] => string(39) "e:\travelloblog\application\controllers"
    ["model_dir"] => string(34) "e:\travelloblog\application\models"
    ["view_dir"] => string(33) "e:\travelloblog\application\views"
    ["view_helper_dir"] => string(47) "e:\travelloblog\library\zf\Travello\View\Helper"
  }
  ["database"] => array(2) {
    ["adapter"] => string(9) "PDO_MYSQL"
    ["params"] => array(4) {
      ["host"] => string(9) "127.0.0.1"
      ["username"] => string(4) "root"
      ["password"] => string(0) ""
      ["dbname"] => string(12) "travelloblog"
    }
  }
}
</pre>
</div>
<p>Du kannst gerne auch einmal ausprobieren, was angezeigt wird, wenn du das "development" beim Erstellen des Zend_Config Objektes durch "production" austauscht. Entferne danach wieder die Ausgabe der Konfigurationsdaten aus der "settings.php" Datei. </p>
<h3><a name="bootstrap">Bootstrap Datei entschlacken</a></h3>
<p>Wie weiter oben bereits erwähnt, habe ich es mir angewöhnt, die Bootstrap Datei so weit wie möglich zu entschlacken und den Aufbau des Systems bzw. das Anlegen diverser Objekte in die "settings.php" auszulagern. </p>
<p>Entferne also als erstes den Abschnitt für die Definition der Datenbankparameter und das Anlegen des Datenbankadapters aus der Bootstrap Datei. Füge dann an das Ende der "settings.php" Datei folgende Zeilen ein:</p>
<div class="igBar"><span id="lphp-114"><a href="#" onclick="javascript:showCodeTxt('php-114'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-114">
<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;">$adapter</span> = <span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">database</span>-&gt;<span style="color:#006600;">adapter</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$params</span>&nbsp; = <span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">database</span>-&gt;<span style="color:#006600;">params</span>-&gt;<span style="color:#006600;">asArray</span><span style="color:#006600; font-weight:bold;">&#40;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$db</span> = Zend_Db::<span style="color:#006600;">factory</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$adapter</span>, <span style="color:#0000FF;">$params</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;">Zend_Db_Table::<span style="color:#006600;">setDefaultAdapter</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$db</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Lade das TravelloBlog im Browser neu und es sollte weiterhin wie gewünscht funktionieren. </p>
<p>Als nächstes entferne bitte den Codeblock für das Erstellen des Zend_Controller_RewriteRouter Objektes bis zum Ablegen im Objektspeicher aus der Bootstrap Datei und füge es an das Ende der "settings.php" Datei wieder ein:</p>
<div class="igBar"><span id="lphp-115"><a href="#" onclick="javascript:showCodeTxt('php-115'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-115">
<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;">$route1</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Controller_Router_Route<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">':controller/:action/:id'</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'controller'</span> =&gt; <span style="color:#FF0000;">'article'</span>, <span style="color:#FF0000;">'action'</span> =&gt; <span style="color:#FF0000;">'index'</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;</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:#0000FF;">$router</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Controller_RewriteRouter<span style="color:#006600; font-weight:bold;">&#40;</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;"><span style="color:#0000FF;">$router</span>-&gt;<span style="color:#006600;">addRoute</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'actionroute'</span>, <span style="color:#0000FF;">$route1</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:#0000FF;">$router</span>-&gt;<span style="color:#006600;">setRewriteBase</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>;&nbsp; <span style="color:#FF9933; font-style:italic;">// change to '/travelloblog/public' for subdirectory</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Zend::<span style="color:#006600;">register</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'router'</span>, <span style="color:#0000FF;">$router</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Die Konfiguration der Routen könnten wir auch in die "settings.ini" Datei ablegen, jedoch würde das einiges an zusätzlicher Tipparbeit ersparen und das Lesen der Routen verschlechtern. Stattdessen belassen wir es vorerst einmal dabei.</p>
<p>Als nächstes entferne den gesamten Codeblock vom Anlegen des Zend_View Objektes bis zum Ablegen im Objektspeicher aus der Bootstrap Datei und füge ihn leicht abgeändert an das Ende der "settings.php" Datei wieder ein:</p>
<div class="igBar"><span id="lphp-116"><a href="#" onclick="javascript:showCodeTxt('php-116'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-116">
<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;">$view</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_View<span style="color:#006600; font-weight:bold;">&#40;</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;"><span style="color:#0000FF;">$view</span>-&gt;<span style="color:#006600;">setScriptPath</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">framework</span>-&gt;<span style="color:#006600;">view_dir</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:#0000FF;">$view</span>-&gt;<span style="color:#006600;">addHelperPath</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">framework</span>-&gt;<span style="color:#006600;">view_helper_dir</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;</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:#0000FF;">$baseurl</span> = <span style="color:#0000FF;">$router</span>-&gt;<span style="color:#006600;">getRewriteBase</span><span style="color:#006600; font-weight:bold;">&#40;</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;"><span style="color:#0000FF;">$view</span>-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'baseurl'</span>, <span style="color:#0000FF;">$baseurl</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Zend::<span style="color:#006600;">register</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'view'</span>, <span style="color:#0000FF;">$view</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Jetzt sieht unsere Bootstrap Datei schon übersichtlicher aus, doch wir können noch weiter gehen. Bitte entschlacke deine Bootstrap Datei nun soweit, dass nur noch diese wenigen Zeilen enthalten sind:</p>
<div class="igBar"><span id="lphp-117"><a href="#" onclick="javascript:showCodeTxt('php-117'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-117">
<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;">require_once</span> <span style="color:#FF0000;">'settings.php'</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$controller</span> = Zend_Controller_Front::<span style="color:#006600;">getInstance</span><span style="color:#006600; font-weight:bold;">&#40;</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:#0000FF;">$controller</span>-&gt;<span style="color:#006600;">setRouter</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$router</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;"><span style="color:#0000FF;">$controller</span>-&gt;<span style="color:#006600;">setControllerDirectory</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">framework</span>-&gt;<span style="color:#006600;">controller_dir</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:#0000FF;">$controller</span>-&gt;<span style="color:#006600;">dispatch</span><span style="color:#006600; font-weight:bold;">&#40;</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;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Die eben entfernten Zeilen füge nun an den Anfang der "settings.php" Datei ein:</p>
<div class="igBar"><span id="lphp-118"><a href="#" onclick="javascript:showCodeTxt('php-118'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-118">
<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;">require_once</span> <span style="color:#FF0000;">'set_include_path.php'</span>;</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;">require_once</span> <span style="color:#FF0000;">'Zend.php'</span>;</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:#000000; font-weight:bold;">function</span> __autoload<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$class</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;"><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; Zend::<span style="color:#006600;">loadClass</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$class</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;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Ein erneutes Laden des TravelloBlogs im Browsers sollte dir zeigen, dass weiterhin alles funktioniert. Die Bootstrap Datei ist nun sehr kurz und enthält nur das wesentliche. Das Laden der Konfigurationseinstellungen und das Anlegen aller benötigten Objekte ist nun in der "settings.php" ausgelagert.</p>
<h3><a name="gesamte-settings">Die gesamte settings.php Datei</a></h3>
<p>Es macht nun eigentlich keinen großen Sinn mehr, für das setzen des "include_path" eine eigene Datei vor zuhalten, so dass du als nächstes die Codezeilen aus der Datei "set_include_path.php" an den Anfang der "settings.php" Datei kopieren und die Datei "set_include_path.php" löschen kannst.</p>
<p>Um mit Hilfe von Zend_Config automatisch die richtigen Konfigurationsdaten für den Entwicklungsrechner und den Liveserver zu laden, ändere den Aufruf nun noch wie folgt ab:</p>
<div class="igBar"><span id="lphp-119"><a href="#" onclick="javascript:showCodeTxt('php-119'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-119">
<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;">$iniFile</span> = <a href="http://www.php.net/dirname"><span style="color:#000066;">dirname</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> . DIRECTORY_SEPARATOR . <span style="color:#FF0000;">'settings.ini'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$section</span> = <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/in_array"><span style="color:#000066;">in_array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$_SERVER</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'HTTP_HOST'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'travelloblog'</span>, <span style="color:#FF0000;">'localhost'</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;">&#41;</span> ? <span style="color:#FF0000;">'development'</span> : <span style="color:#FF0000;">'production'</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:#0000FF;">$config</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Config_Ini<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$iniFile</span>, <span style="color:#0000FF;">$section</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;">Zend::<span style="color:#006600;">register</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'config'</span>, <span style="color:#0000FF;">$config</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Deine komplette "settings.php" Datei sollte nun wie folgt aussehen:</p>
<div class="igBar"><span id="lphp-120"><a href="#" onclick="javascript:showCodeTxt('php-120'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-120">
<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/error_reporting"><span style="color:#000066;">error_reporting</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">E_ALL</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$include_path</span> = <span style="color:#FF0000;">'e:<span style="color:#000099; font-weight:bold;">\t</span>ravelloblog<span style="color:#000099; font-weight:bold;">\l</span>ibrary<span style="color:#000099; font-weight:bold;">\z</span>f'</span> . PATH_SEPARATOR;</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:#0000FF;">$include_path</span>.= <span style="color:#FF0000;">'e:<span style="color:#000099; font-weight:bold;">\t</span>ravelloblog<span style="color:#000099; font-weight:bold;">\a</span>pplication<span style="color:#000099; font-weight:bold;">\m</span>odels'</span> . PATH_SEPARATOR;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$include_path</span>.= <a href="http://www.php.net/get_include_path"><span style="color:#000066;">get_include_path</span></a><span style="color:#006600; font-weight:bold;">&#40;</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;"><a href="http://www.php.net/set_include_path"><span style="color:#000066;">set_include_path</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$include_path</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;</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;">require_once</span> <span style="color:#FF0000;">'Zend.php'</span>;</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:#000000; font-weight:bold;">function</span> __autoload<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$class</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;"><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; Zend::<span style="color:#006600;">loadClass</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$class</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;"><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;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$iniFile</span> = <a href="http://www.php.net/dirname"><span style="color:#000066;">dirname</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> . DIRECTORY_SEPARATOR . <span style="color:#FF0000;">'settings.ini'</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:#0000FF;">$section</span> = <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/in_array"><span style="color:#000066;">in_array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$_SERVER</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'HTTP_HOST'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'travelloblog'</span>, <span style="color:#FF0000;">'localhost'</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;">&#41;</span> ? <span style="color:#FF0000;">'development'</span> : <span style="color:#FF0000;">'production'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$config</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Config_Ini<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$iniFile</span>, <span style="color:#0000FF;">$section</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;">Zend::<span style="color:#006600;">register</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'config'</span>, <span style="color:#0000FF;">$config</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;</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:#0000FF;">$adapter</span> = <span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">database</span>-&gt;<span style="color:#006600;">adapter</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$params</span>&nbsp; = <span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">database</span>-&gt;<span style="color:#006600;">params</span>-&gt;<span style="color:#006600;">asArray</span><span style="color:#006600; font-weight:bold;">&#40;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$db</span> = Zend_Db::<span style="color:#006600;">factory</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$adapter</span>, <span style="color:#0000FF;">$params</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;">Zend_Db_Table::<span style="color:#006600;">setDefaultAdapter</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$db</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;</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:#0000FF;">$route1</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Controller_Router_Route<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">':controller/:action/:id'</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'controller'</span> =&gt; <span style="color:#FF0000;">'article'</span>, <span style="color:#FF0000;">'action'</span> =&gt; <span style="color:#FF0000;">'index'</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;</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:#0000FF;">$router</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Controller_RewriteRouter<span style="color:#006600; font-weight:bold;">&#40;</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;"><span style="color:#0000FF;">$router</span>-&gt;<span style="color:#006600;">addRoute</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'actionroute'</span>, <span style="color:#0000FF;">$route1</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:#0000FF;">$router</span>-&gt;<span style="color:#006600;">setRewriteBase</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>;&nbsp; <span style="color:#FF9933; font-style:italic;">// change to '/travelloblog/public' for subdirectory</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Zend::<span style="color:#006600;">register</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'router'</span>, <span style="color:#0000FF;">$router</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$view</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_View<span style="color:#006600; font-weight:bold;">&#40;</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:#0000FF;">$view</span>-&gt;<span style="color:#006600;">setScriptPath</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">framework</span>-&gt;<span style="color:#006600;">view_dir</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;"><span style="color:#0000FF;">$view</span>-&gt;<span style="color:#006600;">addHelperPath</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">framework</span>-&gt;<span style="color:#006600;">view_helper_dir</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$baseurl</span> = <span style="color:#0000FF;">$router</span>-&gt;<span style="color:#006600;">getRewriteBase</span><span style="color:#006600; font-weight:bold;">&#40;</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:#0000FF;">$view</span>-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'baseurl'</span>, <span style="color:#0000FF;">$baseurl</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;</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;">Zend::<span style="color:#006600;">register</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'view'</span>, <span style="color:#0000FF;">$view</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;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Du kannst nun auch andere Konfigurationsdaten, die du in deinem Projekt benötigst, in der "settings.ini" Datei ablegen. Wann immer du auf diese Daten zugreifen möchtest, kannst du dir das Zend_Config Objekt aus dem Objektspeicher holen und direkt darauf zugreifen:</p>
<div class="igBar"><span id="lphp-121"><a href="#" onclick="javascript:showCodeTxt('php-121'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-121">
<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> = Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'config'</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Da das Thema Zend_Config nun vorerst abgeschlossen ist, wenden wir uns nun noch einige Aufräumarbeiten zu.</p>
<h3><a name="aufraeumarbeiten">Aufräumarbeiten</a></h3>
<p>Wir haben bereits an mehreren Stellen den kleinen Bugfix für das Holen der RewriteBase eingefügt. Es macht durchaus Sinn dafür eine globale Funktion einzuführen, die wir dann später auch entsprechend anpassen können, wenn wir den Bugfix nicht mehr benötigen.</p>
<p>Erstelle also in deiner "settings.php" Datei noch die folgende Funktion:</p>
<div class="igBar"><span id="lphp-122"><a href="#" onclick="javascript:showCodeTxt('php-122'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-122">
<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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></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:#000000; font-weight:bold;">function</span> getRewriteBase<span style="color:#006600; font-weight:bold;">&#40;</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;"><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;">$url</span> = Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'router'</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">getRewriteBase</span><span style="color:#006600; font-weight:bold;">&#40;</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; </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:#616100;">return</span> <span style="color:#0000FF;">$url</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;">&#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;">&nbsp;</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;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Weiter unten in der "settings.php" Datei kannst du dann diese Funktion verwenden:</p>
<div class="igBar"><span id="lphp-123"><a href="#" onclick="javascript:showCodeTxt('php-123'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-123">
<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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></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:#0000FF;">$view</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_View<span style="color:#006600; font-weight:bold;">&#40;</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;"><span style="color:#0000FF;">$view</span>-&gt;<span style="color:#006600;">setScriptPath</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">framework</span>-&gt;<span style="color:#006600;">view_dir</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:#0000FF;">$view</span>-&gt;<span style="color:#006600;">addHelperPath</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$config</span>-&gt;<span style="color:#006600;">framework</span>-&gt;<span style="color:#006600;">view_helper_dir</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;"><span style="color:#0000FF;">$view</span>-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'baseurl'</span>, getRewriteBase<span style="color:#006600; font-weight:bold;">&#40;</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;">Zend::<span style="color:#006600;">register</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'view'</span>, <span style="color:#0000FF;">$view</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;</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;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>In den Controllern ArticleController, TagController und CategoryController kannst du nun die private Methode "getRewriteBase" jeweils entfernen und die Aufrufe von "$this->getRewriteBase()" in "getRewriteBase()" abändern. Das führe ich jetzt hier nicht im Detail auf.</p>
<p>Im ArticleController kannst du nun auch die Methoden listStartpageAction, listCategoryAction und listTagAction entfernen, da wir diese doch nicht benötigen. Die Anzeige aller Artikel auf der Startseite sowie für eine Kategorie oder einen Tag haben wir bereits realisiert.</p>
<h3><a name="fehlerseite">Zentrale 404 Fehlerseite einrichten</a></h3>
<p>Bisher geben unsere __call Methoden in unseren Controllern nur einen kurzen Text aus. Besser wäre es natürlich, wenn alle fehlerhaften Anfragen direkt auf eine zentrale Fehlerseite umgeleitet werden. Diese zentrale Fehlerseite sollte in unserem IndexController aufbereitet werden.</p>
<p>Öffne nun also die Datei "IndexController" im Verzeichnis "/application/controllers" und ändere den vorhandenen Code wie folgt ab:</p>
<div class="igBar"><span id="lphp-124"><a href="#" onclick="javascript:showCodeTxt('php-124'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-124">
<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:#000000; font-weight:bold;">class</span> IndexController extends Travello_Controller_Action</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;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> indexAction<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#0000FF;">$url</span> = getRewriteBase<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> . <span style="color:#FF0000;">'/article'</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; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_redirect<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$url</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:#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;">&nbsp; &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;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> norouteAction<span style="color:#006600; font-weight:bold;">&#40;</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:#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:#0000FF;">$this</span>-&gt;_view-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'title'</span>, <span style="color:#FF0000;">'TravelloBlog - file not found'</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; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_view-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'subtemplate'</span>, <span style="color:#FF0000;">'404.php'</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Status: 404 Not Found"</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:#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;">&nbsp; &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;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> __call<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$methodName</span>, <span style="color:#0000FF;">$args</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:#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:#0000FF;">$url</span> = getRewriteBase<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> . <span style="color:#FF0000;">'/noroute'</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; </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:#0000FF;">$this</span>-&gt;_redirect<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$url</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; &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>
<li style="font-weight: bold;color:#26536A;">
<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>
<p></p>
<p>In der indexAction Methode wird bei einem direkten Aufruf des IndexControllers über den Browser auf den ArticleController umgeleitet. Die Methode norouteAction gibt unsere Fehlerseite sowie den Status Code 404 aus und unsere __call Methode leitet alle fehlerhaften Anfragen auf die 404 Fehlerseite um.</p>
<p>Damit das funktioniert, musst du nun noch im Verzeichnis "/application/views" die Datei "404.php" anlegen:</p>
<div class="igBar"><span id="lphp-125"><a href="#" onclick="javascript:showCodeTxt('php-125'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-125">
<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;">&lt;h2&gt;<span style="color:#CC66CC;color:#800000;">404</span> - An error occured&lt;/h2&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;p&gt;You tried to access a page that does not exist on this server.&lt;/p&gt;</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;">&lt;hr&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;a href=<span style="color:#FF0000;">"/"</span>&gt;back to start page&lt;/a&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Wenn du nun irgendeine nicht vorhandene Seite aufrufen möchtest, sollte dir die Fehlerseite ausgegeben werden. Jetzt kannst du in allen Controllern die Methode __call entsprechend wie im IndexController anpassen. Auch diese Änderungen führe ich nicht im Detail auf.</p>
<h3><a name="bugfixing">Bugfixing</a></h3>
<p>Im letzten Teil haben sich zwei kleine Bugs eingeschlichen. Und zwar werden beim Validieren eines Artikels bereits ausgewählte Kategorien und Tags nicht mehr als selektiert angezeigt. Du kannst das Problem nachstellen, indem du einen neuen Artikel anlegst, dabei Kategorien und Tags auswählst, aber keinen Titel angibst und auf Speichern klickst. Dann sollten beim Verifizieren deine ausgewählten Kategorien und Tags nicht mehr selektiert sein.</p>
<p>Ändere im ArticleController die Methoden createAction und changeAction wie folgt ab:</p>
<div class="igBar"><span id="lphp-126"><a href="#" onclick="javascript:showCodeTxt('php-126'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-126">
<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;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> createAction<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'article'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art_text'</span>&nbsp; <span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">''</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:#0000FF;">$params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'article'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art2cat_cat_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; <span style="color:#0000FF;">$params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'article'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art2tag_tag_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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:#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;">&nbsp; &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;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> changeAction<span style="color:#006600; font-weight:bold;">&#40;</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:#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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'title'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">'TravelloBlog - Update article'</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; </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:#0000FF;">$params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'article'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art2cat_cat_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getCategories</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$art_id</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; &nbsp; &nbsp; <span style="color:#0000FF;">$params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'article'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art2tag_tag_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getTags</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$art_id</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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:#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;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>In der Datei "form.php" im Verzeichnis "/application/views/article" musst du auch zwei kleine Änderungen machen:</p>
<div class="igBar"><span id="lphp-127"><a href="#" onclick="javascript:showCodeTxt('php-127'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-127">
<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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></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:#000000; font-weight:bold;">&lt;?php</span> <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">errors</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art2cat_cat_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> : ?&gt;&lt;div <span style="color:#000000; font-weight:bold;">class</span>=<span style="color:#FF0000;">"error"</span>&gt;&lt;?php <span style="color:#616100;">endif</span>; <span style="color:#000000; font-weight:bold;">?&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">formSelect</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art2cat_cat_id'</span>, <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">article</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art2cat_cat_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'id'</span> =&gt; <span style="color:#FF0000;">'art2cat_cat_id'</span>, <span style="color:#FF0000;">'size'</span> =&gt; <span style="color:#CC66CC;color:#800000;">3</span>, <span style="color:#FF0000;">'multiple'</span> =&gt; <span style="color:#FF0000;">'multiple'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">categories</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#000000; font-weight:bold;">?&gt;</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;">&lt;?php</span> <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">errors</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art2cat_cat_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> : ?&gt;&lt;br/&gt;&lt;?php <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">escape</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">errors</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art2cat_cat_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; ?&gt;&lt;/div&gt;&lt;?php <span style="color:#616100;">endif</span>; <span style="color:#000000; font-weight:bold;">?&gt;</span></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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></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:#000000; font-weight:bold;">&lt;?php</span> <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">errors</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art2tag_tag_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> : ?&gt;&lt;div <span style="color:#000000; font-weight:bold;">class</span>=<span style="color:#FF0000;">"error"</span>&gt;&lt;?php <span style="color:#616100;">endif</span>; <span style="color:#000000; font-weight:bold;">?&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">formSelect</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art2tag_tag_id'</span>, <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">article</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art2tag_tag_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'id'</span> =&gt; <span style="color:#FF0000;">'art2tag_tag_id'</span>, <span style="color:#FF0000;">'size'</span> =&gt; <span style="color:#CC66CC;color:#800000;">5</span>, <span style="color:#FF0000;">'multiple'</span> =&gt; <span style="color:#FF0000;">'multiple'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">tags</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#000000; font-weight:bold;">?&gt;</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;">&lt;?php</span> <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">errors</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art2tag_tag_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> : ?&gt;&lt;br/&gt;&lt;?php <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">escape</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">errors</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art2tag_tag_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; ?&gt;&lt;/div&gt;&lt;?php <span style="color:#616100;">endif</span>; <span style="color:#000000; font-weight:bold;">?&gt;</span></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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Danach sollte dieser Bug bereinigt sein. </p>
<p>Ein zweiter Bug tritt beim Löschen eines Artikels auf. Es werden dann die Einträge in den Tabellen "art2cat" und "art2tag" nicht für den zu löschenden Artikel entfernt. Um das Problem zu lösen, musst du die Methode doDeleteAction im ArticleController entsprechend anpassen:</p>
<div class="igBar"><span id="lphp-128"><a href="#" onclick="javascript:showCodeTxt('php-128'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-128">
<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;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> doDeleteAction<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$article</span>-&gt;<span style="color:#006600;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$where</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$art2tag</span> = <span style="color:#000000; font-weight:bold;">new</span> Art2tagModel<span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; <span style="color:#0000FF;">$where</span> = <span style="color:#0000FF;">$db</span>-&gt;<span style="color:#006600;">quoteInto</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art2tag_art_id = ?'</span>, <span style="color:#0000FF;">$art_id</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; &nbsp; &nbsp; <span style="color:#0000FF;">$art2tag</span>-&gt;<span style="color:#006600;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$where</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$art2cat</span> = <span style="color:#000000; font-weight:bold;">new</span> Art2catModel<span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; <span style="color:#0000FF;">$where</span> = <span style="color:#0000FF;">$db</span>-&gt;<span style="color:#006600;">quoteInto</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art2cat_art_id = ?'</span>, <span style="color:#0000FF;">$art_id</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; &nbsp; &nbsp; <span style="color:#0000FF;">$art2cat</span>-&gt;<span style="color:#006600;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$where</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$url</span> = getRewriteBase<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> . <span style="color:#FF0000;">'/'</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; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_redirect<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$url</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:#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;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Danach sollte auch dieser Bug erledigt sein. Das war es dann auch für dieses Mal. Ausnahmsweise gibt es heute einmal keine Übung.</p>
<h3><a name="download">Download</a></h3>
<p>Der aktuelle Stand des Tutorials nach diesem sechsten Teil kann herunter geladen werden. Hier sind auch alle Templates enthalten. Die Textdateien "empty.txt" in einigen Verzeichnissen habe ich nur angelegt, weil mein Winzip keine leeren Verzeichnisse im Zip Archiv anlegt:</p>
<ul>
<li><a href="http://www.ralfeggert.de/zfw/version-0.8.zip">http://www.ralfeggert.de/zfw/version-0.8.zip</a></li>
</ul>
<p>Die Zip Datei enthält nicht die aktuelle Version des Zend Frameworks. Dies musst du bitte selber in das entsprechende Verzeichnis kopieren. </p>
<h3><a name="zusammenfassung">Zusammenfassung</a></h3>
<p>In diesem achten Teil des Zend Framework Tutorials haben wir die Zend_Config Komponente kennen gelernt und für unser Projekt eingesetzt. Wir haben die Bootstrap Datei stark entschlackt und sämtlichen Code für das Einlesen der Konfigurationsdaten und das Anlegen und Ablegen der Objekte im Objektspeicher in eine separate Datei ausgelagert. Zudem haben wir noch ein wenig aufgeräumt und zwei Bugs bereinigt.</p>
<p>Im nächsten Teil des Tutorials werden wir uns dem Filtern von Benutzereingaben widmen und dabei die Zend_Filter_Input Komponente kennen lernen. Ich habe mich jetzt auch entschieden, die Reihenfolge des Tutorials weiter zu ändern. So werden die beiden geplanten Exkurse zur Integration von Smarty und eZ components an das Ende des Tutorials gestellt. Erst soll die Pflicht kommen, danach dann die Kür... ;-)</p>
<h3><a name="changelog">Change Log</a></h3>
<p>An dieser Stelle werden Änderungen an diesem Tutorial Teil zusammengefasst, die nach dem Ersterscheinen (09.10.2006) notwendig waren, z.B. durch neuere Versionen des Zend Frameworks oder Änderungen am Konzept des Tutorials oder den Anforderungen an unser TravelloBlog.</p>
<ul>
<li>05.11.2006: Tutorial für Release 0.2.0 angepasst</li>
</ul>
<h3><a name="navigation">Navigation</a></h3>
<ul>
<li><a href="http://www.ralfeggert.de/2006/10/02/zend-framework-tutorial-mvc-controller/">Zurück zu Teil 7: MVC Design Pattern für weitere Controller</a></li>
<li><a href="http://www.ralfeggert.de/2006/10/16/zend-framework-tutorial-zend_filter_input/">Weiter zu Teil 9: Benutzereingaben filtern mit Zend_Filter_Input</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ralfeggert.de/2006/10/09/zend-framework-tutorial-zend-config/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Zend Framework Tutorial Teil 7: MVC Design Pattern für weitere Controller</title>
		<link>http://www.ralfeggert.de/2006/10/02/zend-framework-tutorial-mvc-controller/</link>
		<comments>http://www.ralfeggert.de/2006/10/02/zend-framework-tutorial-mvc-controller/#comments</comments>
		<pubDate>Mon, 02 Oct 2006 08:54:15 +0000</pubDate>
		<dc:creator>Ralf Eggert</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.ralfeggert.de/2006/10/02/zend-framework-tutorial-mvc-controller/</guid>
		<description><![CDATA[Im sechsten Teil vom Zend Framework Tutorial hhaben wir mit Hilfe der Zend_View Hilfsmethoden die Formularverarbeitung für unser TravelloBlog erstellt. Wir haben ein Formulartemplate erstellt, die Validierung eingerichtet und die Daten in der Datenbank gespeichert. Zudem haben wir Funktionen für das Ändern und Löschen bestehender Artikel eingerichtet. Wenn du die ersten sechs Teile noch nicht [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ralfeggert.de/2006/09/25/zend-framework-tutorial-mvc-design-pattern-formular-verarbeitung/">Im sechsten Teil</a> vom <strong>Zend Framework Tutorial</strong> hhaben wir mit Hilfe der Zend_View Hilfsmethoden die Formularverarbeitung für unser TravelloBlog erstellt. Wir haben ein Formulartemplate erstellt, die Validierung eingerichtet und die Daten in der Datenbank gespeichert. Zudem haben wir Funktionen für das Ändern und Löschen bestehender Artikel eingerichtet. Wenn du die ersten sechs Teile noch nicht gelesen hast, <a href="http://www.ralfeggert.de/2006/08/26/einfuehrung-und-anforderungen/#aufbau">hole dies bitte schnell nach</a>.</p>
<p>In diesem siebten Teil des Tutorials werden wir nun das MVC Design Pattern für einige weitere <strong>Controller</strong> umsetzen. Neben den Artikeln hast du in den Übungen auch schon einige Funktionalitäten für die Anzeige und Pflege von Kategorien und Tags programmiert. Heute kümmern wir uns darum, die Navigation unseres TravelloBlogs ein wenig umzustrukturieren und die vorhandenen Funktionen mehr miteinander zu verknüpfen. Außerdem werden wir ein wenig intensiver in den <strong>Zend_Controller_RewriteRouter</strong> einsteigen, bestehende Zend Framework Klassen erweitern und unsere erste <strong>Zend_View</strong> Hilfsklasse schreiben. </p>
<p>Wenn du über neue <strong>Tutorial</strong> Teile informiert werden möchtest, abonniere am besten den <a href="http://www.ralfeggert.de/feed/">Feed</a> dieses Blogs. Dann verpasst du garantiert keinen Teil des Tutorials.</p>
<p>Wichtig: Dieses Tutorial setzt die Zend Framework Preview Version 0.2.0 voraus und kann bei der Verwendung einer aktuelleren Version aus dem SVN unter Umständen nicht zu 100% funktionieren. </p>
<p><span id="more-60"></span></p>
<h3>Inhaltsverzeichnis</h3>
<ul>
<li><a href="#zend_controller_rewriterouter">Zend_Controller_RewriteRouter reloaded</a></li>
<li><a href="#startseite">Startseite des TravelloBlogs</a></li>
<li><a href="#kategorien">Kategorien in Navigation verwenden</a></li>
<li><a href="#erweitern">Zend Framework Klassen erweitern</a></li>
<li><a href="#kategorie_anzeigen">Kategorie anzeigen</a></li>
<li><a href="#tagwolke">Wir basteln uns eine Tagwolke</a></li>
<li><a href="#tag_anzeigen">Tag anzeigen</a></li>
<li><a href="#zuordnen">Kategorien zuordnen</a></li>
<li><a href="#articlecontroller">ArticleController überarbeiten</a></li>
<li><a href="#savedata">Methode saveData überarbeiten</a></li>
<li><a href="#artikelanzeige">Artikelanzeige verbessern</a></li>
<li><a href="#uebung">Übung: Tags zuordnen</a></li>
<li><a href="#download">Download</a></li>
<li><a href="#zusammenfassung">Zusammenfassung</a></li>
<li><a href="#changelog">Change log</a></li>
<li><a href="#navigation">Navigation</a></li>
<li><a href="#comments">Kommentare</a></li>
</ul>
<h3><a name="zend_controller_rewriterouter">Zend_Controller_RewriteRouter reloaded</a></h3>
<p>Bereits im <a href="http://www.ralfeggert.de/2006/09/04/zend-framework-tutorial-teil-3-mvc-design-pattern-und-zend_controller/#zend-controller-rewriterouter">dritten Teil dieses Tutorials</a> haben wir bereits die Zend_Controller_RewriteRouter Komponente kennen gelernt. Wir schauen uns dafür einmal einen Ausschnitt aus der aktuellen Bootstrap Datei an, die sich im Verzeichnis "/travelloblog/public/" befindet:</p>
<div class="igBar"><span id="lphp-161"><a href="#" onclick="javascript:showCodeTxt('php-161'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-161">
<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;">$route1</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Controller_Router_Route<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">':controller/:action/:id'</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'action'</span> =&gt; <span style="color:#FF0000;">'index'</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;</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:#0000FF;">$router</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Controller_RewriteRouter<span style="color:#006600; font-weight:bold;">&#40;</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;"><span style="color:#0000FF;">$router</span>-&gt;<span style="color:#006600;">addRoute</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'myroute'</span>, <span style="color:#0000FF;">$route1</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:#0000FF;">$router</span>-&gt;<span style="color:#006600;">setRewriteBase</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>;&nbsp; <span style="color:#FF9933; font-style:italic;">// change to '/travelloblog/public' for subdirectory</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Zend::<span style="color:#006600;">register</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'router'</span>, <span style="color:#0000FF;">$router</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;</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;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$controller</span> = Zend_Controller_Front::<span style="color:#006600;">getInstance</span><span style="color:#006600; font-weight:bold;">&#40;</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:#0000FF;">$controller</span>-&gt;<span style="color:#006600;">setRouter</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$router</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;"><span style="color:#0000FF;">$controller</span>-&gt;<span style="color:#006600;">setControllerDirectory</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$dir</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:#0000FF;">$controller</span>-&gt;<span style="color:#006600;">dispatch</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Der Router wird also bisher initialisiert, es wird eine Route hinzugefügt und dann wird der Router im Objektspeicher registriert. Später wird der Router dann dem Controller hinzugefügt. Doch was macht die Methode addRoute() nun eigentlich genau?</p>
<p>Dazu ein kurzer Blick in die recht kurze, aber schon vorhandene Geschichte des Zend Frameworks. Zu Beginn mit Version 0.1.1 konnte der vorhandene Router nur Adressen im folgendem Format verarbeiten und auf Basis dessen den gewünschten Controller und die gewünschte Aktionsmethode aufrufen. </p>
<div class="textbox">
/article/show/key1/value1/
</div>
<p>Die genannte URL würde die Methode showAction im ArticleController aufrufen und zusätzlich den Parameter "key1" mit dem Wert "value1" belegen. Dieses rudimentäre Routing reicht für einfache Websites aus, aber für ein komplexeres Routing wurde ein flexiblere Router benötigt. Die Idee vom  Zend_Controller_RewriteRouter war geboren.</p>
<p>An dieser Stelle empfehle ich noch einmal die Lektüre des <a href="http://framework.zend.com/manual/de/zend.controller.rewriterouter.html">entsprechenden Kapitels im Manual</a>. Dort wird die grundsätzliche Funktionsweise und die Möglichkeiten gut erläutert. </p>
<p>Zurück zu unserer bereits vorhandenen Route:</p>
<div class="igBar"><span id="lphp-162"><a href="#" onclick="javascript:showCodeTxt('php-162'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-162">
<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;">$route1</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Controller_Router_Route<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">':controller/:action/:id'</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'action'</span> =&gt; <span style="color:#FF0000;">'index'</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;"><span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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:#0000FF;">$router</span>-&gt;<span style="color:#006600;">addRoute</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'myroute'</span>, <span style="color:#0000FF;">$route1</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Jede Route benötigt einen Namen, in unserem Fall haben wir "myroute" verwendet. Die eigentliche Route lautet ":controller/:action/:id". Der Doppelpunkt markiert hier eine Variable, die in einer Aktionsmethode durch die Methode Zend_Controller_Action::_getParam() zugänglich ist. Dabei wird ":controller" immer als Angabe des gewünschten Controllers verwenden und ":action" als Angabe der aufzurufenden Aktionsmethode. Diese beiden Variablen sind also quasi vorbelegt. Zusätzlich können aber beliebig viele weitere Variablen eingeführt werden.</p>
<p>Unsere obige Route passt somit auf alle URLs, die aus drei Teilen bestehen:</p>
<ul>
<li>http://travelloblog/article/show/3</li>
<li>http://travelloblog/article/change/2</li>
<li>http://travelloblog/category/show/this_and_that</li>
</ul>
<p>Der erste Teil gibt den Controller an, der zweite die Aktionsmethode und der dritte landet in der Variablen "id". Diese Id wird z.B. in ArticleController::showAction(),  ArticleController::changeAction() oder CategoryController::showAction() verwendet. </p>
<p>Mit dem dritten Parameter für addRoute() kannst du Variablenwerte vorgeben. Durch die Angabe array('action' => 'index') wird also per Default die indexAction aufgerufen. Im folgenden werden wir immer mal wieder einige neue Routen einführen.</p>
<h3><a name="startseite">Startseite des TravelloBlogs</a></h3>
<p>Beim Aufruf der Startseite des TravelloBlogs erscheint immer noch die eher langweilige Ausgabe "IndexController::indexAction()". Damit per Default die Artikelliste angezeigt wird, müssen wir nur in unserer vorhandenen Route eine kleine Änderung einfügen. Ändere bitte in der Bootstrap Datei die Angabe der Route wie folgt ab:</p>
<div class="igBar"><span id="lphp-163"><a href="#" onclick="javascript:showCodeTxt('php-163'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-163">
<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;">$route1</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Controller_Router_Route<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">':controller/:action/:id'</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'controller'</span> =&gt; <span style="color:#FF0000;">'article'</span>, <span style="color:#FF0000;">'action'</span> =&gt; <span style="color:#FF0000;">'index'</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;</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:#0000FF;">$router</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_Controller_RewriteRouter<span style="color:#006600; font-weight:bold;">&#40;</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;"><span style="color:#0000FF;">$router</span>-&gt;<span style="color:#006600;">addRoute</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'actionroute'</span>, <span style="color:#0000FF;">$route1</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Jetzt soll per Default nicht der IndexController, sondern der ArticleController verwendet werden. Ein Aufruf der Adresse "http://travelloblog/" bestätigt dies. </p>
<p>Um redundante URLs zu vermeiden, bearbeite nun bitte die drei Templates "delete.php", "form.php" und "show.php" im Verzeichnis "/application/view/article" und ändere dort den Link zur Artikelübersicht wie folgt ab:</p>
<div class="igBar"><span id="lhtml-164"><a href="#" onclick="javascript:showCodeTxt('html-164'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">HTML:</span>
<div id="html-164">
<div class="html">
<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: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">"/"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>back to list<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Außerdem musst du nun noch die Datei "ArticleController.php" im Verzeichnis "/application/controller" bearbeiten und dort in den Methoden validateAction und doDeleteAction die Redirects auf die Artikelliste anpassen:</p>
<div class="igBar"><span id="lphp-165"><a href="#" onclick="javascript:showCodeTxt('php-165'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-165">
<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;">$url</span> = <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getRewriteBase</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> . <span style="color:#FF0000;">'/'</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Natürlich ist die Artikelliste auch weiterhin über die Adresse "http://travelloblog/article/" erreichbar, wir verwenden diese Adresse in unserer Applikation aber nun nicht mehr selber.</p>
<h3><a name="kategorien">Kategorien in Navigation verwenden</a></h3>
<p>Als nächstes möchten wir die Navigation ein wenig überarbeiten. Bisher sind in der Navigationsspalte auf der linken Seiten nur Links zu den Listen für Artikel, Tags und Kategorien sowie zum Neuanlegen. Schöne wäre es, wenn wir dort stattdessen die Kategorien verwenden würden. </p>
<p>Als erstes öffnen wir wieder die Datei "ArticleController.php" im Verzeichnis "/application/controllers" und fügen dort eine neue  Methode zum Lesen der Kategorien hinzu:</p>
<div class="igBar"><span id="lphp-166"><a href="#" onclick="javascript:showCodeTxt('php-166'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-166">
<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;">&nbsp; &nbsp; private <span style="color:#000000; font-weight:bold;">function</span> getNavigation<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#0000FF;">$category</span> = <span style="color:#000000; font-weight:bold;">new</span> CategoryModel<span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$order</span>&nbsp; = <span style="color:#FF0000;">'cat_name'</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:#0000FF;">$rowset</span> = <span style="color:#0000FF;">$category</span>-&gt;<span style="color:#006600;">fetchAll</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">null</span>, <span style="color:#0000FF;">$order</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; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$data</span> = <span style="color:#0000FF;">$rowset</span>-&gt;<span style="color:#006600;">toArray</span><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#0000FF;">$data</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:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Diese müssen wir dann in unserer indexAction Methode aufrufen und die Daten an das Template übergeben. Passe also die indexAction Methode wie folgt an:</p>
<div class="igBar"><span id="lphp-167"><a href="#" onclick="javascript:showCodeTxt('php-167'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-167">
<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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$view</span>-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'title'</span>, <span style="color:#FF0000;">'TravelloBlog - List of articles'</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; &nbsp; &nbsp; <span style="color:#0000FF;">$view</span>-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'articles'</span>, <span style="color:#0000FF;">$data</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; &nbsp; &nbsp; <span style="color:#0000FF;">$view</span>-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'navigation'</span>, <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getNavigation</span><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; <span style="color:#0000FF;">$view</span>-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'subtemplate'</span>, <span style="color:#FF0000;">'article/index.php'</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;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Öffne nun bitte die Datei "main.php" im Verzeichnis "/application/views". Wir verschieben die Links zum Neuanlegen in Box 3 und entfernen die Links zu den Tag- und Kategorielisten. Stattdessen geben wir die Navigation aus. Die Datei main.php sollte nun wie folgt aussehen:</p>
<div class="igBar"><span id="lphp-168"><a href="#" onclick="javascript:showCodeTxt('php-168'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-168">
<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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;div id=<span style="color:#FF0000;">"navi"</span>&gt;</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;">&lt;ul&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;li&gt;&lt;a href=<span style="color:#FF0000;">"/"</span>&gt;Homepage&lt;/a&gt;&lt;/li&gt;</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;">&lt;?php</span> <span style="color:#616100;">foreach</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">navigation</span> <span style="color:#616100;">as</span> <span style="color:#0000FF;">$category</span><span style="color:#006600; font-weight:bold;">&#41;</span> : <span style="color:#000000; font-weight:bold;">?&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;li&gt;&lt;a href=<span style="color:#FF0000;">"category/show/&lt;?php echo $this-&gt;escape($category['cat_path']); ?&gt;"</span>&gt;&lt;?php <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">escape</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$category</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'cat_name'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; ?&gt;&lt;/a&gt;&lt;/li&gt;</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;">&lt;?php</span> endforeach; <span style="color:#000000; font-weight:bold;">?&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/ul&gt;</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;">&lt;/div&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;div id=<span style="color:#FF0000;">"extra"</span>&gt;</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;">&lt;div <span style="color:#000000; font-weight:bold;">class</span>=<span style="color:#FF0000;">"extrabox"</span>&gt;Box <span style="color:#CC66CC;color:#800000;">1</span>&lt;/div&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;div <span style="color:#000000; font-weight:bold;">class</span>=<span style="color:#FF0000;">"extrabox"</span>&gt;Box <span style="color:#CC66CC;color:#800000;">2</span>&lt;/div&gt;</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;">&lt;div <span style="color:#000000; font-weight:bold;">class</span>=<span style="color:#FF0000;">"extrabox"</span>&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;ul&gt;</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;">&lt;li&gt;&lt;a href=<span style="color:#FF0000;">"article/create/"</span>&gt;create <span style="color:#000000; font-weight:bold;">new</span> article&lt;/a&gt;&lt;/li&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;li&gt;&lt;a href=<span style="color:#FF0000;">"tag/create/"</span>&gt;create <span style="color:#000000; font-weight:bold;">new</span> tag&lt;/a&gt;&lt;/li&gt;</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;">&lt;li&gt;&lt;a href=<span style="color:#FF0000;">"category/create/"</span>&gt;create <span style="color:#000000; font-weight:bold;">new</span> category&lt;/a&gt;&lt;/li&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/ul&gt;</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;">&lt;/div&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/div&gt;</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;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Wenn du nun die Adresse "http://travelloblog/" aufrufst, sollte die Startseite des Blogs wie folgt aussehen:</p>
<p><img id="image55" src="http://www.ralfeggert.de/wp-content/uploads/2006/10/7-screen1.png" alt="Screen 1: Navigation" /></p>
<p>Doch nun haben wir ein kleines Problem. In jeder Aktionsmethode, welche unser Haupttemplate verarbeitet und ausgeben soll, müssten wir nun die Liste der Kategorien ermitteln und an das Template übergeben. Diese Änderung müssten wir jetzt schon in 11 Aktionsmethoden nachpflegen, später kommen sicher weitere Aktionsmethoden hinzu. Außerdem müssten wir die Methode getNavigation() auch in jedem unserer Controller hinein kopieren. Ich denke, da hat niemand große List darauf.</p>
<p>Das Problem ließe sich einfach lösen, wenn wir die Zend_Controller_Action Klasse anpassen und mit unseren gewünschten Funktionen erweitern könnten. Doch geht das überhaupt? Natürlich geht das und sogar recht einfach, da das Zend Framework darauf ausgelegt ist, dass du es einfach erweitern kannst.</p>
<h3><a name="erweitern">Zend Framework Klassen erweitern</a></h3>
<p>Wenn du eine bestehende Klasse aus dem Zend Framework erweitern möchtest, bietet es sich an, für deine erweiterte Klasse das gleiche Schema für die Benennung der Klasse und die Lage der Datei zu verwenden. So liegt die Klasse Zend_Controller_Action z.B. im Verzeichnis "Zend/Controller/" und heißt "Action.php". Wenn wir das gleiche Schema verwenden, können wir das früher eingeführte Autoloading auch für unsere erweiterten Klassen verwenden.</p>
<p>Lege bitte im Verzeichnis "/library/zf" das Unterverzeichnis "Travello" und darunter das Verzeichnis "Controller", so dass du nun ein Verzeichnis "/library/zf/Travello/Controller" hast. Dort legst du die Datei "Action.php" mit folgendem Code an:</p>
<div class="igBar"><span id="lphp-169"><a href="#" onclick="javascript:showCodeTxt('php-169'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-169">
<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;">abstract <span style="color:#000000; font-weight:bold;">class</span> Travello_Controller_Action extends Zend_Controller_Action</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;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; protected <span style="color:#0000FF;">$_view</span> = <span style="color:#000000; font-weight:bold;">null</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; protected <span style="color:#0000FF;">$_template</span> = <span style="color:#FF0000;">'main.php'</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; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; protected <span style="color:#0000FF;">$_vars</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</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; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> __construct<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_view = Zend::<span style="color:#006600;">registry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'view'</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:#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;">&nbsp; &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;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> __destruct<span style="color:#006600; font-weight:bold;">&#40;</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:#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:#0000FF;">$this</span>-&gt;_view-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'navigation'</span>, <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getNavigation</span><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$this</span>-&gt;_view-&gt;<span style="color:#006600;">render</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;_template<span style="color:#006600; font-weight:bold;">&#41;</span>;&nbsp; &nbsp; <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;"><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:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Wir führen zuerst einige geschützte Eigenschaften ein. "$_view" wird für das Speichern der Zend_View Instanz verwendet, in "$_template" legen wir den Namen des Haupttemplates ab und in "$_vars" werden alle Templatevariablen abgelegt.</p>
<p>Im Konstruktor holen wir uns die Instanz von Zend_View und legen sie in unserer Eigenschaft "$_view" ab. Im Destruktor werden die Daten für die Navigation geholt und das Template verarbeitet und ausgegeben.</p>
<p>Im nächsten Schritt öffne bitte alle Controller Klassen im Verzeichnis "/application/controllers" und ändere die Deklaration so ab, dass die Klassen ab sofort nicht mehr Zend_Controller_Action sondern Travello_Controller_Action erweitern. Jetzt schließe bitte alle Controller Klassen mit Ausnahme von ArticleController, CategoryController und TagController.</p>
<p>Jetzt kannst du alle Zeilen entfernen, in denen die Instanz von Zend_View aus dem Objektspeicher geholt wird, sowie alle Zeilen, in denen das Template verarbeitet und ausgeben wird. Danach musst du noch alle Aufrufe von "$view->assign" in "$this->_view->assign" umwandeln sowie den Aufruf von getNavigation() aus der indexAction Methode im ArticleController entfernen. Als Beispiel zeige ich einmal die indexAction Methode vom ArticleController:</p>
<div class="igBar"><span id="lphp-170"><a href="#" onclick="javascript:showCodeTxt('php-170'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-170">
<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;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> indexAction<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#0000FF;">$article</span> = <span style="color:#000000; font-weight:bold;">new</span> ArticleModel<span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$order</span>&nbsp; = <span style="color:#FF0000;">'art_cdate DESC'</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:#0000FF;">$rowset</span> = <span style="color:#0000FF;">$article</span>-&gt;<span style="color:#006600;">fetchAll</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">null</span>, <span style="color:#0000FF;">$order</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; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$data</span> = <span style="color:#0000FF;">$rowset</span>-&gt;<span style="color:#006600;">toArray</span><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_view-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'title'</span>, <span style="color:#FF0000;">'TravelloBlog - List of articles'</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; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_view-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'articles'</span>, <span style="color:#0000FF;">$data</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; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_view-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'subtemplate'</span>, <span style="color:#FF0000;">'article/index.php'</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:#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:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p> </p>
<p>Diese Änderungen musst du in den Methoden buildForm, indexAction, showAction und deleteAction in den Controllern ArticleController, CategoryController und TagController durchführen.</p>
<p>Zum Schluss müssen wir nun nur noch die Methode getNavigation aus dem ArticleController in die neue Klasse Travello_Controller_Action verschieben. Wenn du nun das TravelloBlog wieder im Browser aufrufst, sollte alles noch wie vorher funktionieren und zudem hast du auf jeder Seite die Navigation mit den Kategorien eingebunden.</p>
<h3><a name="kategorie_anzeigen">Kategorie anzeigen</a></h3>
<p>Wenn du auf eine der Kategorien in der Navigation klickst, wird momentan nur die Kategorie selber, aber nicht die zugeordneten Artikel ausgegeben. Das ist natürlich eher suboptimal. Also ändern wir als erstes die showAction Methode im CategoryController wie folgt ab:</p>
<div class="igBar"><span id="lphp-171"><a href="#" onclick="javascript:showCodeTxt('php-171'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-171">
<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;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> showAction<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#0000FF;">$path</span> = <span style="color:#0000FF;">$this</span>-&gt;_getParam<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'id'</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; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$category</span> = <span style="color:#000000; font-weight:bold;">new</span> CategoryModel<span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; <span style="color:#0000FF;">$db</span> = <span style="color:#0000FF;">$category</span>-&gt;<span style="color:#006600;">getAdapter</span><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; <span style="color:#0000FF;">$where</span> = <span style="color:#0000FF;">$db</span>-&gt;<span style="color:#006600;">quoteInto</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'cat_path = ?'</span>, <span style="color:#0000FF;">$path</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; &nbsp; &nbsp; <span style="color:#0000FF;">$row</span> = <span style="color:#0000FF;">$category</span>-&gt;<span style="color:#006600;">fetchRow</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$where</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; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$data</span> = <span style="color:#0000FF;">$row</span>-&gt;<span style="color:#006600;">toArray</span><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$select</span> = <span style="color:#0000FF;">$db</span>-&gt;<span style="color:#006600;">select</span><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; <span style="color:#0000FF;">$select</span>-&gt;<span style="color:#006600;">from</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'article'</span>, <span style="color:#FF0000;">'*'</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; &nbsp; &nbsp; <span style="color:#0000FF;">$select</span>-&gt;<span style="color:#006600;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art2cat'</span>, <span style="color:#FF0000;">'art_id = art2cat_art_id'</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; &nbsp; &nbsp; <span style="color:#0000FF;">$select</span>-&gt;<span style="color:#006600;">where</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art2cat_cat_id = ?'</span>, <span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'cat_id'</span><span style="color:#006600; font-weight:bold;">&#93;</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; &nbsp; &nbsp; <span style="color:#0000FF;">$select</span>-&gt;<span style="color:#006600;">order</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art_cdate DESC'</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; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$articles</span> = <span style="color:#0000FF;">$db</span>-&gt;<span style="color:#006600;">fetchAll</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$select</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; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_view-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'title'</span>, <span style="color:#FF0000;">'TravelloBlog - '</span> . <span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'cat_name'</span><span style="color:#006600; font-weight:bold;">&#93;</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; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_view-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'articles'</span>, <span style="color:#0000FF;">$articles</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; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_view-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'category'</span>, <span style="color:#0000FF;">$data</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; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_view-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'subtemplate'</span>, <span style="color:#FF0000;">'category/show.php'</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:#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;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Da Zend_Db_Table bisher noch keine Joins von Tabellen unterstützt, verwenden wir der Einfachheit halber die Zend_Db_Select Komponente, die ich bisher noch nicht ausführlich vorgestellt habe. Ich denke aber, dass du mit <a href="http://framework.zend.com/manual/de/zend.db.select.html">Hilfe des Manuals</a> schnell herausfinden kannst, was hier im einzelnen passiert. Die gelesenen Artikel werden dann ebenfalls an das Template übergeben.</p>
<p>Als nächstes musst du noch das Template "show.php" im Verzeichnis "/application/views/category" öffnen und entsprechend wie folgt ändern:</p>
<div class="igBar"><span id="lphp-172"><a href="#" onclick="javascript:showCodeTxt('php-172'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-172">
<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> <span style="color:#616100;">foreach</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">articles</span> <span style="color:#616100;">as</span> <span style="color:#0000FF;">$article</span><span style="color:#006600; font-weight:bold;">&#41;</span> : <span style="color:#000000; font-weight:bold;">?&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;h2&gt;&lt;a href=<span style="color:#FF0000;">"article/show/&lt;?php echo $this-&gt;escape($article['art_id']); ?&gt;"</span>&gt;&lt;?php <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">escape</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$article</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art_title'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; ?&gt;&lt;/a&gt;&lt;/h2&gt;</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;">&lt;p&gt;&lt;em&gt;&lt;?php <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">escape</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$article</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art_cdate'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; ?&gt;&lt;/em&gt;&lt;/p&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;p&gt;&lt;?php <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">escape</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$article</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'art_teaser'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; ?&gt;&lt;/p&gt;</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;">&lt;hr&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> endforeach; <span style="color:#000000; font-weight:bold;">?&gt;</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;">&lt;a href=<span style="color:#FF0000;">"category/"</span>&gt;back to list&lt;/a&gt; | </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;a href=<span style="color:#FF0000;">"category/change/&lt;?php echo $this-&gt;escape($this-&gt;category['cat_path']); ?&gt;"</span>&gt;change category&lt;/a&gt; | </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;">&lt;a href=<span style="color:#FF0000;">"category/delete/&lt;?php echo $this-&gt;escape($this-&gt;category['cat_path']); ?&gt;"</span>&gt;delete category&lt;/a&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Wenn du dir nun eine Kategorie im Browser anzeigen lässt, wird eine Liste aller dieser Kategorie zugeordneten Artikel ausgegeben:</p>
<p><img id="image56" src="http://www.ralfeggert.de/wp-content/uploads/2006/10/7-screen2.png" alt="Screen 2: Liste aller Artikel einer Kategorien" /></p>
<h3><a name="tagwolke">Wir basteln uns eine Tagwolke</a></h3>
<p>Als nächstes möchten wir uns eine Tagwolke basteln, die gut in – sagen wir – die noch freie Box 1 auf der rechten Seite platzieren können. Wir haben in den vorherigen Abschnitten bereits gesehen, wie man Zend_Controller_Action Klasse für die Liste der Kategorien erweitern kann. Dies führen wir nun auch für unsere Tagwolke durch.</p>
<p>Rufe also wieder die Datei "Action.php" im Verzeichnis "/library/zf/Travello/Controller" auf und füge dort die neue private Methode getTagcloud ein und übergeben im Destruktor die Daten an die Templatevariable "tagcloud":</p>
<div class="igBar"><span id="lphp-173"><a href="#" onclick="javascript:showCodeTxt('php-173'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-173">
<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;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; private <span style="color:#000000; font-weight:bold;">function</span> getTagcloud<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#0000FF;">$tag</span> = <span style="color:#000000; font-weight:bold;">new</span> TagModel<span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; <span style="color:#0000FF;">$db</span> = <span style="color:#0000FF;">$tag</span>-&gt;<span style="color:#006600;">getAdapter</span><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$select</span> = <span style="color:#0000FF;">$db</span>-&gt;<span style="color:#006600;">select</span><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; <span style="color:#0000FF;">$select</span>-&gt;<span style="color:#006600;">from</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'tag'</span>, <span style="color:#FF0000;">'tag.*, COUNT(tag_id) AS tag_count'</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; &nbsp; &nbsp; <span style="color:#0000FF;">$select</span>-&gt;<span style="color:#006600;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'art2tag'</span>, <span style="color:#FF0000;">'tag_id = art2tag_tag_id'</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; &nbsp; &nbsp; <span style="color:#0000FF;">$select</span>-&gt;<span style="color:#006600;">order</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'tag_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; &nbsp; &nbsp; <span style="color:#0000FF;">$select</span>-&gt;<span style="color:#006600;">group</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'tag_id'</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; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$tags</span> = <span style="color:#0000FF;">$db</span>-&gt;<span style="color:#006600;">fetchAll</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$select</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; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#0000FF;">$tags</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;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> __destruct<span style="color:#006600; font-weight:bold;">&#40;</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:#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; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_view-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'navigation'</span>, <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getNavigation</span><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;_view-&gt;<span style="color:#006600;">assign</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'tagcloud'</span>, <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getTagcloud</span><span style="color:#006600; font-weight:bold;">&#40;</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; &nbsp; &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;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$this</span>-&gt;_view-&gt;<span style="color:#006600;">render</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;_template<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:#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;">&nbsp;</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;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</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>
<p></p>
<p>Öffne nun bitte wieder die Datei "main.php" im Verzeichnis "/application/views" und gebe unsere Tagwolke in der Box 1 auf der rechten Seite aus:</p>
<div class="igBar"><span id="lphp-174"><a href="#" onclick="javascript:showCodeTxt('php-174'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-174">
<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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;div id=<span style="color:#FF0000;">"extra"</span>&gt;</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;">&lt;div <span style="color:#000000; font-weight:bold;">class</span>=<span style="color:#FF0000;">"extrabox"</span>&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;h3&gt;Tagcloud&lt;/h3&gt;</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;">&lt;ul&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> <span style="color:#616100;">foreach</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">tagcloud</span> <span style="color:#616100;">as</span> <span style="color:#0000FF;">$tag</span><span style="color:#006600; font-weight:bold;">&#41;</span> : <span style="color:#000000; font-weight:bold;">?&gt;</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;">&lt;li&gt;&lt;a href=<span style="color:#FF0000;">"tag/show/&lt;?php echo $this-&gt;escape($tag['tag_path']); ?&gt;"</span>&gt;&lt;?php <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">escape</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$tag</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'tag_name'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; ?&gt;&lt;/a&gt; <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">escape</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$tag</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'tag_count'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#000000; font-weight:bold;">?&gt;</span><span style="color:#006600; font-weight:bold;">&#41;</span>&lt;/li&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> endforeach; <span style="color:#000000; font-weight:bold;">?&gt;</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;">&lt;/ul&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/div&gt;</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;">&lt;div <span style="color:#000000; font-weight:bold;">class</span>=<span style="color:#FF0000;">"extrabox"</span>&gt;Box <span style="color:#CC66CC;color:#800000;">2</span>&lt;/div&gt;</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;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Die Tagwolke ist nun zwar schon vorhanden, sieht aber noch nicht so besonders schön aus. Die Ausgabe sollte in etwa wie folgt aussehen:</p>
<p><img id="image57" src="http://www.ralfeggert.de/wp-content/uploads/2006/10/7-screen3.png" alt="Screen 3: Tagwolke 1" /></p>
<p>Um die Ausgabe der Tagwolke ein wenig schicker zu machen, legen wir dafür nun eine eigene Zend_View Hilfsklasse an. Da ich diese nicht im Zend Framework Verzeichnis, sondern in dem Baum mit unseren abgeleiteten Klassen platzieren möchte, müssen wir Zend_View noch mitteilen, ein weiteres Verzeichnis mit Zend_View Hilfsklassen zu beachten. Öffne dafür die Bootstrap Datei index.php im Verzeichnis "/public" und ergänzte die Konfiguration von Zend_View mit einer Zeile:</p>
<div class="igBar"><span id="lphp-175"><a href="#" onclick="javascript:showCodeTxt('php-175'); return false;">Quellcode (klicken)</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-175">
<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:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></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:#0000FF;">$view</span> = <span style="color:#000000; font-weight:bold;">new</span> Zend_View<span style="color:#006600; font-weight:bold;">&#40;</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;"><span style="color:#0000FF;">$view</span>-&gt;<span style="color:#006600;">setScriptPath</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'../application/views'</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:#0000FF;">$view</span>-&gt;<span style="color:#006600;">addHelperPath</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'e:<span style="color