<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PHP Log &#187; views</title>
	<atom:link href="http://www.php-log.de/tags/views/feed" rel="self" type="application/rss+xml" />
	<link>http://www.php-log.de</link>
	<description>Eine feine Sammlung nützlicher PHP Notizen</description>
	<lastBuildDate>Thu, 27 May 2010 04:43:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>CakePHP &#8211; Einfluss auf die Paginator URL nehmen</title>
		<link>http://www.php-log.de/372/php/cakephp-einfluss-auf-die-paginator-url-nehmen</link>
		<comments>http://www.php-log.de/372/php/cakephp-einfluss-auf-die-paginator-url-nehmen#comments</comments>
		<pubDate>Wed, 17 Jun 2009 09:54:35 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Pagination]]></category>
		<category><![CDATA[views]]></category>

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

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

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

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

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

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

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

]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/337/php/cakephp/cakephp-die-undokumentierte-sort-methode-im-paginator/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP &#8211; Ein Template in eine Variable rendern</title>
		<link>http://www.php-log.de/263/php/cakephp-ein-template-in-eine-variable-rendern</link>
		<comments>http://www.php-log.de/263/php/cakephp-ein-template-in-eine-variable-rendern#comments</comments>
		<pubDate>Tue, 28 Apr 2009 13:32:06 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=263</guid>
		<description><![CDATA[Oft genug kommt man als PHP Programmierer in die Situation ein Template rendern zu müssen, ohne es aber an den Browser senden zu wollen. Das ist z.B. Regelmäßig der Fall wenn die Daten z.B. in einer Datei gespeichert werden sollen oder wenn eine E-Mail verschickt wird. Das Cake-Handbuch hilft an dieser Stelle nicht weiter, auch [...]]]></description>
			<content:encoded><![CDATA[<p>Oft genug kommt man als PHP Programmierer in die Situation ein Template rendern zu müssen, ohne es aber an den Browser senden zu wollen. Das ist z.B. Regelmäßig der Fall wenn die Daten z.B. in einer Datei gespeichert werden sollen oder wenn eine E-Mail verschickt wird.<span id="more-263"></span></p>
<p>Das Cake-Handbuch hilft an dieser Stelle nicht weiter, auch Google ist bei dieser Frage nicht sehr ergiebig. Die Lösung ist jedoch recht einfach, man muss nur drauf kommen. Die &lt;code&gt;element()&lt;/code&gt; Methode der View Klasse eignet sich hervorragend für diesen Zweck, einziges Problem ist das die Methode nicht in den Controllern zur Verfügung steht. Dem ist aber leicht Abhilfe geschafft:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$View</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> View<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$View</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">element</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pfad/zum/template&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/263/php/cakephp-ein-template-in-eine-variable-rendern/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Radio Buttons mit dem CakePHP Forms Helper</title>
		<link>http://www.php-log.de/188/php/radio-buttons-mit-dem-cakephp-forms-helper</link>
		<comments>http://www.php-log.de/188/php/radio-buttons-mit-dem-cakephp-forms-helper#comments</comments>
		<pubDate>Tue, 17 Feb 2009 06:38:25 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=188</guid>
		<description><![CDATA[Der Forms Helper von CakePHP ist schon recht flexibel, jedoch, manchmal muss man schon ein wenig &#8220;rumbiegen&#8221; um ihn zum gewünschten Ergebniss zu bewegen. Da dazu das Erzeugen von Radios nicht so gut dokumentiert ist hier nun ein wenig Sample-Code für das Erzeugen von Radio Buttons: &#60;?php $options = array&#40; // Anweisung keine Label für [...]]]></description>
			<content:encoded><![CDATA[<p>Der Forms Helper von CakePHP ist schon recht flexibel, jedoch, manchmal muss man schon ein wenig &#8220;rumbiegen&#8221; um ihn zum gewünschten Ergebniss zu bewegen. Da dazu das Erzeugen von Radios nicht so gut dokumentiert ist hier nun ein wenig Sample-Code für das Erzeugen von Radio Buttons:<span id="more-188"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #000088;">$options</span> <span style="color: #339933;">=</span>  <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
		<span style="color: #666666; font-style: italic;">// Anweisung keine Label für die einzelnen Felder zu erzeugen</span>
		<span style="color: #0000ff;">'label'</span> 	<span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
		<span style="color: #666666; font-style: italic;">// Stattdessen ein Label vor die Felder</span>
		<span style="color: #0000ff;">'before'</span> 	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;label for=&quot;radios-primary&quot;&gt;Art des Ausweises&lt;/label&gt;'</span><span style="color: #339933;">,</span>
		<span style="color: #666666; font-style: italic;">// Ohne die Type Angabe wird es ein &lt;select&gt;</span>
		<span style="color: #0000ff;">'type'</span> 		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'radio'</span><span style="color: #339933;">,</span>
		<span style="color: #666666; font-style: italic;">// Den Standard festlegen</span>
		<span style="color: #0000ff;">'default'</span> 		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span>
		<span style="color: #666666; font-style: italic;">// Legend aus</span>
		<span style="color: #0000ff;">'legend'</span> 	<span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
		<span style="color: #666666; font-style: italic;">// Die Werte als Key -&gt; Value Pairs übergeben</span>
		<span style="color: #0000ff;">'options'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">' Personalausweis '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'passport'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">' Reisepass '</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'passtype'</span><span style="color: #339933;">,</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/188/php/radio-buttons-mit-dem-cakephp-forms-helper/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Attribute an den CakePHP Form Helper</title>
		<link>http://www.php-log.de/158/php/attribute-an-den-cakephp-form-helper</link>
		<comments>http://www.php-log.de/158/php/attribute-an-den-cakephp-form-helper#comments</comments>
		<pubDate>Tue, 10 Feb 2009 18:26:24 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=158</guid>
		<description><![CDATA[In der Dokumentation über den Form Helper von CakePHP geht ein wenig unter dass man an den $options Parameter auch beliebige Key -Value Pairs übergeben kann. Möchte man das Formular vor dem Absenden noch ein wenig validieren geht kann man 'onsubmit' => 'validation()' definieren. Ein Beispiel: echo $form-&#62;create&#40;'User', array&#40;'onsubmit' =&#62; 'if( is_invalid() ) return false;'&#41;&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>In der Dokumentation über den <a href="http://book.cakephp.org/de/view/183/Formulare-erstellen" target="_blank">Form Helper</a> von CakePHP geht ein wenig unter dass man an den $options Parameter auch beliebige Key -Value Pairs übergeben kann. Möchte man das Formular vor dem Absenden noch ein wenig validieren geht kann man <code>'onsubmit' => 'validation()' </code>definieren. Ein Beispiel:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'User'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'onsubmit'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'if( is_invalid() ) return false;'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><span id="more-158"></span>Ja, ich weiß es steht in der Doku, aber nicht so explizit <img src='http://www.php-log.de/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/158/php/attribute-an-den-cakephp-form-helper/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PDF bearbeiten mit Zend Framework in einer CakePHP Anwendung</title>
		<link>http://www.php-log.de/150/php/pdf-bearbeiten-mit-zend-framework-in-einer-cakephp-anwendung</link>
		<comments>http://www.php-log.de/150/php/pdf-bearbeiten-mit-zend-framework-in-einer-cakephp-anwendung#comments</comments>
		<pubDate>Tue, 10 Feb 2009 04:23:28 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Media Views]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=150</guid>
		<description><![CDATA[Es gibt zur Zeit noch keine PDF Unterstützung in CakePHP. Auch in der Bakery gibt es nur ein Tutorial für die Entwicklung mit TCPDF, aber  danach steht mir heute nicht der Sinn. Vielmehr reizt es mich CakePHP mit dem Zend Framework zu verheiraten. Die Komponente Zend_Pdf kann PDF&#8217;s einlesen, bzw. neu anlegen, beschreiben, speichern und [...]]]></description>
			<content:encoded><![CDATA[<p>Es gibt zur Zeit noch keine PDF Unterstützung in CakePHP. Auch in der <a href="http://bakery.cakephp.org/categories/view/3" target="_blank">Bakery</a> gibt es nur ein Tutorial für die Entwicklung mit <a href="http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf" target="_blank">TCPDF</a>, aber  danach steht mir heute nicht der Sinn. Vielmehr reizt es mich CakePHP mit dem Zend Framework zu verheiraten. Die Komponente Zend_Pdf kann PDF&#8217;s einlesen, bzw. neu anlegen, beschreiben, speichern und noch einges mehr. Ein schönes Stück Software.<span id="more-150"></span></p>
<p>CakePHP ist auf dass Einbinden fremder Libraries vorbereitet und bietet dem Zend Framework den Ordner /vendors als Quartier. Über die Konstante <strong>VENDORS</strong> kann dann auch fleissig inkludiert werden. Da ich gleich das ganze Zend Framework in den Vendor Ordner gepackt ist es nur konsequent diesen in den include_path einzubinden:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// /app/config/bootstrap.php</span>
<span style="color: #990000;">set_include_path</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">get_include_path</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PATH_SEPARATOR <span style="color: #339933;">.</span> VENDORS <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Danach kann es auch im Controller schon losgehen:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> view<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Die Zend_Pdf Komponente einbinden</span>
	<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Zend/Exception.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Zend/Pdf/Exception.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Zend/Pdf.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Ein bestehendes PDF öffnen</span>
	<span style="color: #000088;">$pdf</span> <span style="color: #339933;">=</span> Zend_Pdf<span style="color: #339933;">::</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span>VIEWS <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;shares/share_template.pdf&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Einen Font einrichten und registrieren</span>
	<span style="color: #000088;">$font</span> <span style="color: #339933;">=</span> Zend_Pdf_Font<span style="color: #339933;">::</span><span style="color: #004000;">fontWithName</span><span style="color: #009900;">&#40;</span>Zend_Pdf_Font<span style="color: #339933;">::</span><span style="color: #004000;">FONT_TIMES_ROMAN</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pages</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFont</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$font</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// In das PDF schreiben</span>
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pages</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">drawText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hello World, how are you doing?&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">60</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">710</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Und dann schön speichern (Ausserhalb des Webroot)</span>
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span>APP<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;files/shares/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.pdf&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Einen Media View für die Ausgabe/Download einrichten</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Media'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	       <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.pdf&quot;</span><span style="color: #339933;">,</span>
	       <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'HelloWorld'</span><span style="color: #339933;">,</span>
	       <span style="color: #0000ff;">'download'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
	       <span style="color: #0000ff;">'extension'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'pdf'</span><span style="color: #339933;">,</span>
	       <span style="color: #0000ff;">'path'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'files'</span> <span style="color: #339933;">.</span> DS <span style="color: #339933;">.</span> <span style="color: #0000ff;">'shares'</span> <span style="color: #339933;">.</span> DS
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Der Umgang mit der Komponente Zend_Pdf wird <a target="_blank" href="http://framework.zend.com/manual/de/zend.pdf.drawing.html">hier</a> ausführlich erläutert. An dieser Stelle will ich nur den Prozess als ganzes beleuchten. Also&#8230;Ich habe die view Methode eines Controllers so eingerichtet dass nicht mehr HTML ausgeben wird, sondern ein dynamisch beschriebenes PDF.  Was neben der Einbindung des Zend Frameworks noch interessant ist sind die <a target="_blank" href="http://book.cakephp.org/de/view/489/Media-Views">Media Views</a>, die Ihre Entsprechung in der <a target="_blank" href="http://api.rubyonrails.org/classes/ActionController/Streaming.html#M000401">send_file</a> Methode von Ruby On Rails finden.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/150/php/pdf-bearbeiten-mit-zend-framework-in-einer-cakephp-anwendung/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
