<?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>Athlan • Piotr Pelczar • blog programisty &#187; Zend framework</title>
	<atom:link href="http://athlan.pl/kategoria/zend-framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://athlan.pl</link>
	<description>Napisać kod zrozumiały dla komputera potrafi byle głupek. Dobrzy programiści tworzą kod zrozumiały dla człowieka...</description>
	<lastBuildDate>Tue, 14 Feb 2012 14:33:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>How to send template and layout mail with Zend_Mail</title>
		<link>http://athlan.pl/send-template-layout-mail-with-zend_mail/</link>
		<comments>http://athlan.pl/send-template-layout-mail-with-zend_mail/#comments</comments>
		<pubDate>Tue, 14 Feb 2012 14:33:21 +0000</pubDate>
		<dc:creator>Athlan</dc:creator>
				<category><![CDATA[Planeta]]></category>
		<category><![CDATA[Solutions]]></category>
		<category><![CDATA[Zend framework]]></category>
		<category><![CDATA[Zend_Layout]]></category>
		<category><![CDATA[Zend_View]]></category>
		<category><![CDATA[Zned_Mail]]></category>

		<guid isPermaLink="false">http://athlan.pl/?p=779</guid>
		<description><![CDATA[Zend_Mail provides a great and simple in use and configuration mechanizm to send emails. The problem begins when you would like to specify fully templated and layouted messages. In my current project I have several kinds of mails: customer invoices and messages, users notifications, admin notifications, webmaster email about critical errors in scheduled system tasks. [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Zend_Mail</strong></em> provides a great and simple in use and configuration mechanizm to send emails. The problem begins when you would like to specify fully templated and layouted messages.</p>
<p>In my current project I have several kinds of mails: customer invoices and messages, users notifications, admin notifications, webmaster email about critical errors in scheduled system tasks. In this case the <em><strong>Zend_Layout</strong></em> fits perfectly to redner rich text content by <em><strong>Zend_View</strong></em>, but it is implemented in <em>Zend_Mail</em>, wchih provies simply <em>setBodyText()</em> and <em>setBodyHTML()</em> methods.</p>
<p>This inconvenience is understandable by the way, mainly in context simpe, clear and flexible extendable code of Zend Framework. We will strive to extend the functionality od Zend_Mail following ZF developers concepts.</p>
<h2>Overview</h2>
<p>Writing class extending Zend_Mail I kept a several concepts:</p>
<ul>
<li>Messages should be both templated and layouted using <em>Zend_View</em> and <em>Zend_Layout</em>.</li>
<li>The email view scripts (templates) there are in main view scripts directory nested in subdirectory (as deep as you want).</li>
<li>&#8230; The same path story with layouts.</li>
<li>You can use this object excatly the same way as <em>Zend_Mail</em>. It behaviour the same way as parent until you set special options (like point to view script path or file to render in body).</li>
<li>&#8230; and object should keep <em>Zend_Mail</em> fluent interface (returning <em>$this</em> in setters) to provide <a href="http://en.wikipedia.org/wiki/Fluent_interface#PHP">method chaining fluent interface</a>.</li>
<li>Pointed view file is rendered as a mail body.</li>
<li><span style="text-decoration: underline;">You can use this object excatly the same way as <em>Zend_Mail</em></span>. It behaviour the same way as parent until you set special options (like point to view script path or file to render in body).</li>
</ul>
<h2>Zend_Mail application.ini configuration and extending application</h2>
<p>Simply paste several lines to <code>application.ini</code> configuration, theare are self-commented, description is not neccessary at this point. We will use <a href="http://framework.zend.com/manual/en/zend.mail.smtp-authentication.html">SMTP transport</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">resources.mail.transport.type <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> smtp</span>
resources.mail.transport.host <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> YOUR_HOSTNAME</span>
resources.mail.transport.auth <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> login</span>
resources.mail.transport.username <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;YOUR_ACCOUNT&quot;</span>
resources.mail.transport.password <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;YOUR_PASSWORD&quot;</span>
resources.mail.transport.register <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> true</span>
&nbsp;
resources.mail.defaultFrom.email <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> YOUR_ACCOUNT</span>
resources.mail.defaultFrom.name <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;MyService.com&quot;</span>
resources.mail.defaultReplyTo.email <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> YOUR_ACCOUNT</span>
resources.mail.defaultReplyTo.name <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;MyService.com&quot;</span></pre></div></div>

<p>In addition we will create tho additional directories and files:</p>
<ul>
<li><code>/application/views/scripts/email/</code>-  just add a subdirectory /email to existing view scripts directory.</li>
<li><code>/application/layouts/scripts/email/</code> &#8211; the same story as above</li>
</ul>
<div><strong>TIP:</strong> I have moved default configured layouts direcotry to <code>/application/views/layouts/</code> to unify structure of application. Just change in <code>application.ini</code> this line:</div>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">resources.layout.layoutPath <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> APPLICATION_PATH </span><span style="color: #933;">&quot;/modules/default/views/layouts/scripts/&quot;</span></pre></div></div>

<p>To test our class let&#8217;s create additional two files:</p>
<p><code>/application/layouts/scripts/email/<strong>html.phtml</strong></code></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">layout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;--&lt;</span>br <span style="color: #339933;">/&gt;</span>Best Regards<span style="color: #339933;">,&lt;</span>br <span style="color: #339933;">/&gt;</span>MyService<span style="color: #339933;">.</span>com<span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span></pre></div></div>

<p>and scond one, the information about successfull account register with your own content:</p>
<p><code>/application/views/scripts/email/<strong>AccountRegister.phtml</strong></code></p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;p&gt;Thanks for register.&lt;/p&gt;</pre></div></div>

<h2>ZentUtil_Mail class usage</h2>
<p>Before we will write a code, let&#8217;s think abous its usage, wchih should be the same as in <a href="http://framework.zend.com/manual/en/zend.mail.introduction.html">Zend_Mail documentation</a> witch additional methods:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$mail</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ZendUtil_Mail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'utf-8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addTo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'athlanster@gmail.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Piotr Pelczar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setSubject</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Testowy mail z zenda'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setBodyView</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'AccountRegister.phtml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Above code should send mail from <code>AccountRegister.phtml</code> view script nested in <code>html.phtml</code> layout.</p>
<p>If you want to change layout simply call <code>setViewLayoutScript($script)</code> method with string or set <code>false</code> to disable layouts. For change paths <code>setViewPathDirectory($path)</code>, <code>setViewLayoutPathDirectory($path)</code> are available.</p>
<h2>ZendUtil_Mail extends Zend_Mail</h2>
<p>ZendUtil_Mail has been extended by Zend_Mail and <code>_prepareBody()</code> method has been added. It is called just before <code>parent::send()</code> method.</p>
<ul>
<li><strong><a href="http://athlan.pl/code/Mail">Download the ZendUtil_Mail source code.</a></strong></li>
</ul>
<p><strong>NOTE:</strong> I have added <code>ZendUtil_</code> namespace.</p>
<p>I hope it will help.</p>
]]></content:encoded>
			<wfw:commentRss>http://athlan.pl/send-template-layout-mail-with-zend_mail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get single error message with Zend_Validate_EmailAddress validation</title>
		<link>http://athlan.pl/single-error-message-zend_validate_emailaddress/</link>
		<comments>http://athlan.pl/single-error-message-zend_validate_emailaddress/#comments</comments>
		<pubDate>Mon, 13 Feb 2012 23:45:09 +0000</pubDate>
		<dc:creator>Athlan</dc:creator>
				<category><![CDATA[Planeta]]></category>
		<category><![CDATA[Solutions]]></category>
		<category><![CDATA[Zend framework]]></category>
		<category><![CDATA[Zend_Validate]]></category>

		<guid isPermaLink="false">http://athlan.pl/?p=763</guid>
		<description><![CDATA[I have just started introducing Zend Framework when I had to face the problem with output multiple error messages in form while email address validation. Checking domain (whith is enabled by default) causes additional error messages indicates anomalies in hostname segment of provided by user email address. In result, we receive several errors assigned to [...]]]></description>
			<content:encoded><![CDATA[<p>I have just started introducing Zend Framework when I had to face the problem with output multiple error messages in form while email address validation. Checking domain (whith is enabled by default) causes additional error messages indicates anomalies in hostname segment of provided by user email address. In result, we receive several errors assigned to one email field.</p>
<p>The problem is easy to slove by overriding default behaviour of Zend_Validate_EmailAddress clearing all messages generating while validation and setup a new single error message.</p>
<p>Simply add namespace <em>MyOwn_</em> for own needs and provide class in file <code>/libraries/MyOwn/Validate/EmailAddess.php</code></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MyOwn_Validate_EmailAddress <span style="color: #000000; font-weight: bold;">extends</span> Zend_Validate_EmailAddress
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">const</span> INVALID <span style="color: #339933;">=</span> <span style="color: #0000ff;">'emailAddressInvalid'</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_messageTemplates</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">INVALID</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Invalid Email Address.&quot;</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> isValid<span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    parent<span style="color: #339933;">::</span><span style="color: #004000;">setOptions</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'allow'</span> <span style="color: #339933;">=&gt;</span> Zend_Validate_Hostname<span style="color: #339933;">::</span><span style="color: #004000;">ALLOW_DNS</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'domain'</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;">'mx'</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;">'deep'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>parent<span style="color: #339933;">::</span><span style="color: #004000;">isValid</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_messages <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// clear all previous messages</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_error<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">INVALID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And provide above custom validator to form element in <code>/application/forms/AccountRegister.php</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Form_AccountRegister <span style="color: #000000; font-weight: bold;">extends</span> Zend_Form
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMethod</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post'</span><span style="color: #009900;">&#41;</span>
         <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Account_Register'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Form_Element_Text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$email</span>
      <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLabel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Email address'</span><span style="color: #009900;">&#41;</span>
      <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addValidator</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ZendUtil_Validate_EmailAddress<span style="color: #009900;">&#41;</span>
      <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRequired</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addElement</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>NOTE:</strong></p>
<ul>
<li>In addition, you can simply translate the <em>emailAddressInvalid</em> message.</li>
<li>For sticklers, setting options in <em>isValid</em> method is hardcoded with look like a messy code, but it is quick-fix</li>
</ul>
<p>Hope it will help.</p>
]]></content:encoded>
			<wfw:commentRss>http://athlan.pl/single-error-message-zend_validate_emailaddress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upload filmów z Zend_Gdata_YouTube</title>
		<link>http://athlan.pl/upload-filmow-zend_gdata_youtube/</link>
		<comments>http://athlan.pl/upload-filmow-zend_gdata_youtube/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 14:00:56 +0000</pubDate>
		<dc:creator>Athlan</dc:creator>
				<category><![CDATA[Planeta]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Przemyślenia]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Zend framework]]></category>
		<category><![CDATA[gdata]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[youtube]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://athlan.pl/?p=148</guid>
		<description><![CDATA[Pisząc nowy projekt natknąłem na problem z procesem uploadu filmiku do serwisu YouTube. Sam upload jest bardzo łatwy do napisania z Zend_Gdata_YouTube &#8211; przykład można znaleźć w manualu. Myślę, że zainteresowani przeczytają manual i wszystko będzie jasne. Więc jeżeli to takie proste, to w czym problem? Zakładamy, że userzy uloadują filmiki bezpośrednio na nasz serwis. [...]]]></description>
			<content:encoded><![CDATA[<p>Pisząc <a href="http://athlan.pl/videoblog/">nowy projekt</a> natknąłem na problem z procesem uploadu filmiku do serwisu YouTube. Sam upload jest bardzo łatwy do napisania z <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/App/Zend_Gdata_YouTube.html">Zend_Gdata_YouTube</a> &#8211; <a href="http://framework.zend.com/manual/en/zend.gdata.youtube.html#zend.gdata.youtube.uploads.example">przykład</a> można znaleźć w manualu. Myślę, że zainteresowani przeczytają manual i wszystko będzie jasne. Więc jeżeli to takie proste, to w czym problem?</p>
<p>Zakładamy, że userzy uloadują filmiki bezpośrednio na nasz serwis. Nasz serwer ma za zadanie:</p>
<ol>
<li>Skompresować video i zapisać go w formacie flv.</li>
<li>Nałożyć watermark.</li>
<li>Wysłać obrobiony film do serwisu Youtube logując się na zdefiniowane przez użytkownika konto lub założone przez administratora strony.</li>
</ol>
<p>Pierwsze 2 kroki wykonają się błyskawicznie w porównaniu do trzeciego. Kompresja i nałożenie watermarku na 30 megowy plik z wykorzystaniem FFMPEG to nic nadzwyczajnego. Natomiast wysyłka pliku na serwery Youtube&#8217;a może zawiesić apache&#8217;a, gdy jest ich kilka.</p>
<p>Rozwiązanie? Wpadłem na pomysł, aby upload filmików ustawiony był w pewnego rodzaju kolejce, która uruchamiana by była co minutę (cron), a czas jednego wysłania elemntu nie mógłby przekroczyć 50 sekund. Oczywiście takie działanie uruchamiałoby swój osobny proces apache&#8217;a. Ten sposób jest ograniczony dwoma limitami: wielkością pliku oraz czasem jego uploadu na serwer (jednocześniem interwałem uruchamiania kolejki).</p>
]]></content:encoded>
			<wfw:commentRss>http://athlan.pl/upload-filmow-zend_gdata_youtube/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
