<?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; Media Views</title>
	<atom:link href="http://www.php-log.de/tags/media-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>Mon, 20 Sep 2010 00:22:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>CakePHP &#8211; Form Helper vom Type Date zeigt nur englische Monatsnamen</title>
		<link>http://www.php-log.de/282/php/cakephp-form-helper-vom-type-date-zeigt-nur-englische-monatsnamen</link>
		<comments>http://www.php-log.de/282/php/cakephp-form-helper-vom-type-date-zeigt-nur-englische-monatsnamen#comments</comments>
		<pubDate>Tue, 12 May 2009 00:13:15 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[localisation]]></category>
		<category><![CDATA[Media Views]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=282</guid>
		<description><![CDATA[Dieses Problem ist schon seit 10 Monaten bekannt und es gibt auch einen Patch dafür, aber aus irgendeinem Grund hat er seinen Weg noch nicht in aktuelle Release gefunden. Die Lösung ist hier skizziert https://trac.cakephp.org/ticket/5127]]></description>
			<content:encoded><![CDATA[<p>Dieses Problem ist schon seit 10 Monaten bekannt und es gibt auch einen Patch dafür, aber aus irgendeinem Grund hat er seinen Weg noch nicht in aktuelle Release gefunden. <span id="more-282"></span></p>
<p>Die Lösung ist hier skizziert <a href="https://trac.cakephp.org/ticket/5127" target="_blank">https://trac.cakephp.org/ticket/5127</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/282/php/cakephp-form-helper-vom-type-date-zeigt-nur-englische-monatsnamen/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Downloads mit CakePHP</title>
		<link>http://www.php-log.de/193/php/downloads-mit-cakephp</link>
		<comments>http://www.php-log.de/193/php/downloads-mit-cakephp#comments</comments>
		<pubDate>Tue, 10 Mar 2009 13:17:16 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[Media Views]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=193</guid>
		<description><![CDATA[Über die Vorteile und Funktion der Media Views von CakePHP habe ich ja schon gesprochen. Wenn man den Codeschnipsel der dort zur Verfügung gestellt wird ein wenig erweitert und in den Application Controller packt, erhält man mit wenigen Handgriffen ein feines Download Center. class AppController extends Controller &#123; &#160; function download&#40;&#41;&#123; // Extrahiere die Dateiname [...]]]></description>
			<content:encoded><![CDATA[<p>Über die Vorteile und Funktion der <a href="http://book.cakephp.org/de/view/489/Media-Views" target="_blank">Media Views</a> von CakePHP habe ich ja schon gesprochen. Wenn man den Codeschnipsel der dort zur Verfügung gestellt wird ein wenig erweitert und in den Application Controller packt, erhält man mit wenigen Handgriffen ein feines Download Center.<span id="more-193"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> AppController <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> download<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Extrahiere die Dateiname und Typ aus der URL</span>
		<span style="color: #666666; font-style: italic;">// Die Url hat das Format /controller/download/extension/file</span>
		<span style="color: #666666; font-style: italic;">// Beispiel /users/download/pdf/flyer</span>
		<span style="color: #000088;">$extension</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pass'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pass'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$download_folder</span> <span style="color: #339933;">=</span> WWW_ROOT<span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Gib einen 404er aus wenn die Datei nicht existiert</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$download_folder</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$file</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;.&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$extension</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cakeError</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error404'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Sende die Datei an den Browser</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;">$file</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;.&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$extension</span><span style="color: #339933;">,</span>
		       <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$file</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: #000088;">$extension</span><span style="color: #339933;">,</span>
		       <span style="color: #0000ff;">'path'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$download_folder</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Diese Methode dient nur als Basis für weitere Feinheiten, so kann man z.B. prüfen ob der User zum Download berechtigt ist, einen Zähler einbauen und vieles mehr. Da diese Methode in den Application Controller gesteckt wurde kann Sie überall eingesetzt werden. /users/download/pdf/fyler funktioniert genauso wie /clients/download/pdf/flyer. </p>
<p>In diesem Fall wird davon ausgegangen dass die Dateien direkt im Webroot abgelegt sind, wer einen anderen Ablageort bevorzugt passt die Variable $download_folder an.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/193/php/downloads-mit-cakephp/feed</wfw:commentRss>
		<slash:comments>1</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[php]]></category>
		<category><![CDATA[Zend Framework]]></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>2</slash:comments>
		</item>
	</channel>
</rss>

