<?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>I want to be free &#187; zend</title>
	<atom:link href="http://i1t2b3.com/category/zend/feed/" rel="self" type="application/rss+xml" />
	<link>http://i1t2b3.com</link>
	<description>Any fool can make things bigger and more complex</description>
	<lastBuildDate>Wed, 11 Apr 2012 12:59:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Zend View Helpers inheritance</title>
		<link>http://i1t2b3.com/2010/04/06/zend-view-helpers-inheritance/</link>
		<comments>http://i1t2b3.com/2010/04/06/zend-view-helpers-inheritance/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 16:01:38 +0000</pubDate>
		<dc:creator>Skakunov Alexander</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://i1t2b3.com/?p=591</guid>
		<description><![CDATA[It&#8217;s handy to use View Helpers in Zend FW driven project. For example, you want to make an in-place tracker (e.g. Google Analytics) &#8212; you create a helper class My_View_Helper_Tracker inherited from Zend_View_Helper, Zend finds its automatically and then you are free to use your helper method: echo $this->tracker( $trackerID ); The question is what [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s handy to use <noindex><a rel="nofollow" href="http://framework.zend.com/manual/en/zend.view.helpers.html">View Helpers</a></noindex> in Zend FW driven project. For example, you want to make an in-place tracker (e.g. Google Analytics) &mdash; you create a helper class My_View_Helper_Tracker inherited from Zend_View_Helper, Zend finds its automatically and then you are free to use your helper method:</p>
<pre><code>echo $this->tracker( $trackerID );</code></pre>
<p>The question is what you gonna do if you want a base class for a family of trackers?</p>
<p>It&#8217;s not so obvoius due to naming conventions.</p>
<p>Let&#8217;s say you want 2 kinds of trackers: Google Analytics and Euroads.</p>
<p>1. You create such files structure:</p>
<pre><code>
library
 - My
   - View
    - Helper
      - Tracker
        Abstract.php
        - Google
          Page.php
        - Euroads
          Owner.php
          Guest.php
</code></pre>
<p>2. You name your classes as:</p>
<ul>
<li>My_View_Helper_Tracker_Euroads_Guest (extends My_View_Helper_Tracker_Abstract)</li>
<li>&#8230; so on &#8230;</li>
</ul>
<p>3. Class methods are:</p>
<pre><code class="php">public function tracker_euroads_guest(...) ...</code></pre>
<p>4. And the trickiest part: the helper call:</p>
<pre><code class="php">echo $this->tracker_<strong>E</strong>uroads_<strong>G</strong>uest</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://i1t2b3.com/2010/04/06/zend-view-helpers-inheritance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Currency exchange in your application</title>
		<link>http://i1t2b3.com/2009/09/28/currency-exchange/</link>
		<comments>http://i1t2b3.com/2009/09/28/currency-exchange/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 10:53:17 +0000</pubDate>
		<dc:creator>Skakunov Alexander</dc:creator>
				<category><![CDATA[db]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[ideas]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://i1t2b3.com/?p=555</guid>
		<description><![CDATA[That&#8217;s easy, you need 2 things: Fresh currencies exchange rates Some way to excange amount from one currency to another. This how I did it: get values from European Central Bank (ECB) for step #1 and wrote MySQL user defined function for step #2. Here is how to export currencies rates from ECB (EUR is [...]]]></description>
			<content:encoded><![CDATA[<p>That&#8217;s easy, you need 2 things:</p>
<ol>
<li>Fresh currencies exchange rates</li>
<li>Some way to excange amount from one currency to another.</li>
</ol>
<p>This how I did it: get values from European Central Bank (ECB) for step #1 and wrote MySQL user defined function for step #2.</p>
<p>Here is how to export currencies rates from ECB (EUR is a base currency, and I add self rate as 1:1). First I create such  database table:</p>
<pre><code class="sql">CREATE TABLE IF NOT EXISTS `currency` (
  `code` char(3) NOT NULL DEFAULT '',
  `rate` decimal(10,5) NOT NULL COMMENT 'Rate to EUR got from www.ecb.int',
  PRIMARY KEY (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Currency rates (regularly updated)';
</code></pre>
<p>Now let&#8217;s fill it with rates:</p>
<pre><code class="php">&lt;?php

class CurrencyController extends Controller_Ajax_Action {

  public function importAction() {

    $db = Zend_Registry::get('db');
    $db-&gt;beginTransaction();

    $url = 'http://www.ecb.int/stats/eurofxref/eurofxref.zip?1c7a343768baab4322620e3498553b5a';
    try {
      $contents = file_get_contents($url);
      $contents = archive::unzip($contents);
      $contents = explode(&quot;\n&quot;, $contents);

      $names = explode(',', $contents[0]);
      $rates = explode(',', $contents[1]);

      $names[] = 'EUR';
      $rates[] = 1;

      for ($i = 1; $i &lt; sizeof($names); $i++) {
        if (!(float) $rates[$i]) continue;
        $db-&gt;query( sprintf('INSERT INTO `currency`(`code`, `rate`)
              VALUES (&quot;%s&quot;, %10.5f)
              ON DUPLICATE KEY UPDATE `rate`=VALUES(`rate`)',
             trim( $names[$i] ),
             trim( $rates[$i] )
        ) );
      }

      $db-&gt;commit();
    } catch ( Exception $O_o ) {
      error_log( $O_o-&gt;getMessage() );
      $db-&gt;rollback();
    }

  }
}</code></pre>
<p>Now let&#8217;s create a SQL function for handy converts. Create a <code>udf.sql</code> file and add this in it:</p>
<pre><code class="sql">DELIMITER //

DROP  FUNCTION IF EXISTS EXCHANGE;
CREATE FUNCTION EXCHANGE( amount DOUBLE, cFrom CHAR(3), cTo CHAR(3) ) RETURNS DOUBLE READS SQL DATA DETERMINISTIC
    COMMENT 'converts money amount from one currency to another'
BEGIN
    DECLARE rateFrom DOUBLE DEFAULT 0;
    DECLARE rateTo DOUBLE DEFAULT 0;

    SELECT `rate` INTO rateFrom FROM `currency` WHERE `code` = cFrom;
    SELECT `rate` INTO rateTo   FROM `currency` WHERE `code` = cTo;

    IF ISNULL( rateFrom ) OR ISNULL( rateTo ) THEN
        RETURN NULL;
    END IF;

    RETURN amount * rateTo / rateFrom;
END; //

DELIMITER ;</code></pre>
<p>and run this command in your shell:</p>
<pre><code>mysql --user=USER --password=PASS DATABASE &lt; udf.sql</code></pre>
<p>This is how you can use this function &mdash; how to convert 10 US dollars to Canadian dollars:</p>
<pre><code class="sql">SELECT EXCHANGE( 10, 'USD', 'CAD')</code></pre>
<p>which results in $10 = 10.93 Canadian dollars.</p>
<p>P.S. Consider adding the currency export action call to your cron scripts.</p>
<p>P.P.S. A function to unzip the data file can be got at <noindex><a rel="nofollow" href="http://ua2.php.net/manual/en/ref.zip.php">php.net</a></noindex></p>
]]></content:encoded>
			<wfw:commentRss>http://i1t2b3.com/2009/09/28/currency-exchange/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax controller in Zend project</title>
		<link>http://i1t2b3.com/2009/09/22/ajax-controller-in-zend-project/</link>
		<comments>http://i1t2b3.com/2009/09/22/ajax-controller-in-zend-project/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 14:34:35 +0000</pubDate>
		<dc:creator>Skakunov Alexander</dc:creator>
				<category><![CDATA[ideas]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://i1t2b3.com/?p=543</guid>
		<description><![CDATA[I want to share a couple of features I use to handle AJAX requests in projects based on Zend Framework. 1. AJAX request handling What: some parts of your application can be not loaded if currect request is AJAX. Why: you don&#8217;t need views, templates, some routes &#8212; so you can add an AJAX check [...]]]></description>
			<content:encoded><![CDATA[<p>I want to share a couple of features I use to handle AJAX requests in projects based on Zend Framework.</p>
<h3>1. AJAX request handling</h3>
<p><strong>What</strong>: some parts of your application can be not loaded if currect request is AJAX.</p>
<p><strong>Why</strong>: you don&#8217;t need views, templates,  some routes &mdash; so you can add an AJAX check in your Initializer or bootstrap file and avoid loading not necessary things.</p>
<p><strong>How</strong>: Zend Request object has a <noindex><a rel="nofollow" href="http://framework.zend.com/manual/en/zend.controller.request.html#zend.controller.request.http.ajax"><code>isXmlHttpRequest</code> method</a></noindex> to find out whether it&#8217;s AJAX request or not. It&#8217;s based on &#8216;<code>X-Requested-With</code>&#8216; header, which is sent by jQuery, Prototype, Scriptaculous, YUI and MochiKit frameworks.</p>
<h3>2. AJAX Controller</h3>
<p>Most AJAX controller&#8217;s methods I saw had an <code>exit()</code> inside to not to output Zend&#8217;s template &mdash; it is a work-around. The proper way to do so is to tell to Zend not to load anything. One step forward is to create an abstract Controller class and inherit all you AJAX classes from it:</p>
<p><code>/library/Koodix/Controller/Ajax/Action.php</code>:</p>
<pre><code>&lt;?php

require_once 'Zend/Controller/Action.php';

abstract class Koodix_Controller_Ajax_Action
  extends Zend_Controller_Action
{
    public function init() {
        //disable the standard layout output
        $this-&gt;_helper-&gt;layout()-&gt;disableLayout();
        $this-&gt;_helper-&gt;viewRenderer-&gt;setNoRender();
    }

    public function postDispatch() {
        //envelope and output json field
            if( !empty( $this-&gt;json ) ) {
                echo json_encode( $this-&gt;json );
            }
        }
}</code></pre>
<p><code>/application/modules/default/controllers/AjaxController.php</code>:</p>
<pre><code>&lt;?php

class AjaxController extends Koodix_Controller_Ajax_Action
{
 // bla-bla-bla
</code></pre>
<p>Take a look at <code>postDispatch</code> method &mdash; idea behind it is to convert to JSON and output anything that is set to <code>json</code> field of your controller. If you want to send JSON data in special header (and not in body, like it&#8217;s done in my example), you can do it in this method.</p>
]]></content:encoded>
			<wfw:commentRss>http://i1t2b3.com/2009/09/22/ajax-controller-in-zend-project/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flash uploader and HTTP password protection</title>
		<link>http://i1t2b3.com/2009/09/11/how-to-skip-http-password-by-flash-uploader/</link>
		<comments>http://i1t2b3.com/2009/09/11/how-to-skip-http-password-by-flash-uploader/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 16:24:43 +0000</pubDate>
		<dc:creator>Skakunov Alexander</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[ideas]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://i1t2b3.com/?p=535</guid>
		<description><![CDATA[You are working on a project and you want to protect the beta version with password so that only allowed people (beta testers) could access it. You decide not to invent the wheel and to use the standard HTTP authentication. First idea is to use your Apache web server to do this, so you write [...]]]></description>
			<content:encoded><![CDATA[<p>You are working on a project and you want to protect the beta version with password so that only allowed people (beta testers) could access it.</p>
<p>You decide not to invent the wheel and to use the standard HTTP authentication.</p>
<p>First idea is to use your Apache web server to do this, so you write something like that in <code>.htaccess</code> file: </p>
<pre><code>AuthName "Private zone"
AuthType Basic
AuthUserFile /path/to/.htpasswd
require valid-use</code></pre>
<p>This solution is simple and that&#8217;s why good.</p>
<p>A problem comes on stage when a Flash <a href="http://www.aurigma.com/file-upload.aspx">file uploader</a> is added to your project &#8211; usually it cannot &#8220;login&#8221; to your site, i.e. users are not able to use the Flash file uploader behind beta login.</p>
<p>That&#8217;s how I solved it.</p>
<p>It&#8217;s not the web server who must solve this (Apache), it&#8217;s the application server (PHP). So remove the lines above from <code>.htaccess</code> and use <noindex><a rel="nofollow" href="http://framework.zend.com/manual/en/zend.auth.adapter.http.html">Zend_Auth_Adapter_Http</a></noindex>  for this purpose &mdash; it&#8217;s Zend&#8217;s HTTP Authentication Adapter.</p>
<p>What concerns the Flash uploader: it sends &#8216;Shockwave Flash&#8217; as value of &#8216;User-Agent&#8217; request header. So in your Initializer or Bootstrap file (where you load Zend_Auth_Adapter_Http) check this header value, and if it&#8217;s not Flash&#8217;s, go for HTTP authentication.</p>
<p>P.S. Hackers can assume this and fake the header to access your site. To cope with that, use an additional secret request variable (Flash uploaders allow this) and check it at server side.</p>
]]></content:encoded>
			<wfw:commentRss>http://i1t2b3.com/2009/09/11/how-to-skip-http-password-by-flash-uploader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Auth Session Expiration Time</title>
		<link>http://i1t2b3.com/2009/07/08/zend-auth-session-expiration-time/</link>
		<comments>http://i1t2b3.com/2009/07/08/zend-auth-session-expiration-time/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 11:02:52 +0000</pubDate>
		<dc:creator>Skakunov Alexander</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://i1t2b3.com/?p=439</guid>
		<description><![CDATA[After authentication in my project it takes about 10-20 minutes for the auth session to expire, which is not handy &#8212; you go to get a snack and see a login screen coming back. This is how to make the TTL of your auth session longer: $s = new Zend_Session_Namespace( $this-&#62;_auth-&#62;getStorage()-&#62;getNamespace() ); $s-&#62;setExpirationSeconds( strtotime('30 day', [...]]]></description>
			<content:encoded><![CDATA[<p>After authentication in my project it takes about 10-20 minutes for the auth session to expire, which is not handy &mdash; you go to get a snack and see a login screen coming back.</p>
<p>This is how to make the <acronym title="Time To Live">TTL</acronym> of your auth session longer:</p>
<pre><code class="php">$s = new Zend_Session_Namespace(
    $this-&gt;_auth-&gt;getStorage()-&gt;getNamespace() );

$s-&gt;setExpirationSeconds( strtotime('30 day', 0) );</code></pre>
<p>Now your users will log in for 30 days.</p>
<p>You can call this code in your login action after successful authentication and before the redirect to the landing page.</p>
]]></content:encoded>
			<wfw:commentRss>http://i1t2b3.com/2009/07/08/zend-auth-session-expiration-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

