<?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/"
	>

<channel>
	<title>ThinkRobot &#187; Zend</title>
	<atom:link href="http://think-robot.com/tag/zend/feed/" rel="self" type="application/rss+xml" />
	<link>http://think-robot.com</link>
	<description>Design &#38; Development Blog</description>
	<pubDate>Sat, 06 Mar 2010 20:58:13 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Zend_Db_Select multiple table joins explained</title>
		<link>http://think-robot.com/2009/04/zend_db_select-multiple-table-joins-explained/</link>
		<comments>http://think-robot.com/2009/04/zend_db_select-multiple-table-joins-explained/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 22:52:23 +0000</pubDate>
		<dc:creator>Joanna</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Tutorials]]></category>

		<category><![CDATA[ORM]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[SQL]]></category>

		<category><![CDATA[Zend]]></category>

		<category><![CDATA[Zend Framework]]></category>

		<category><![CDATA[Zend_Db_select]]></category>

		<category><![CDATA[Zend_Db_Table_Abstract]]></category>

		<guid isPermaLink="false">http://think-robot.com/?p=156</guid>
		<description><![CDATA[It sounds like a simple task - retrieve the result from a join SQL query. Unusually you can even find documentation on the official Zend Framework site explaining how to put together a query that will return the results from a JOIN query. Unfortunately when it actually comes to putting theory into practice any Zend [...]]]></description>
			<content:encoded><![CDATA[<p>It sounds like a simple task - retrieve the result from a join SQL query. Unusually you can even find <a href="http://framework.zend.com/manual/en/zend.db.select.html" target="_blank">documentation on the official Zend</a> Framework site explaining how to put together a query that will return the results from a JOIN query. Unfortunately when it actually comes to putting theory into practice any Zend newcomer can run into several problems.<span id="more-156"></span></p>
<h2>You Think It&#8217;s Easy&#8230;</h2>
<p>For starters rather than use &#8220;raw&#8221; <strong>Zend_Db_Select</strong>:</p>
<pre><code><code>$select = $db-&gt;select();</code></code></pre>
<p>I wanted to derive the select from my <strong>Zend_Db_Table_Abstract</strong>, like so:</p>
<pre><code><code>
class Model_Db_Website extends Zend_Db_Table_Abstract {
	(...)
	public function fetchWebsites(){
		$select = $this-&gt;select();
		$select-&gt;join(array('whi' =&gt; 'website_has_images), 'whi.website_id = websites.website_id')
		return $this-&gt;fetchAll($select);
	}
}
</code></code></pre>
<p>This was more or less the example I found in the documentation. You might be wondering what is wrong with this picture. At first it seems like there is nothing missing. The table fields and the table name (for the FROM clause) are taken from the table class, and we have provided all the necessary JOIN details&#8230; However instead of the expected result, you an error message!</p>
<pre class="msg"><code><strong>Message:</strong> Select query cannot join with another table </code></code></pre>
<h2>The Solution</h2>
<p>Not to prolong any more here is the final bit, which we will walk-through below.</p>
<pre><code><code>
class Model_Db_Website extends Zend_Db_Table_Abstract {
	(...)
	public function fetchWebsites(){
		$select = $this-&gt;select();
		$select<strong>-&gt;setIntegrityCheck(false)</strong>
			<strong>-&gt;from($this-&gt;_name, '*')</strong>
			-&gt;join(
				array('whi' =&gt; 'website_has_images'),
				'whi.website_id = websites.website_id'<strong>, '*'</strong>
    			);
		return $this-&gt;fetchAll($select);
	}
}
</code></code></pre>
<p>The first thing you need to do is get rid of the error. This one has been mentioned online quite a lot and is easy to fix by applying:</p>
<pre class="msg"><code>-&gt;setIntegrityCheck(false)</code></code></pre>
<p>The code above makes your result set read only, but allows you to do joins.</p>
<p>Now for the less obvious bits. Once the above problem is fixed you will notice that your results only include the join table fields. To fix this add the final parameter to the list - either a &#8216;*&#8217; or an explicit list of fields.</p>
<p><strong>Many sites suggest using an empty array, though this causes the result set to return only main table fields&#8230;</strong></p>
<p>The &#8216;*&#8217; is not enough though. You still need the from declaration <strong>-&gt;from($this-&gt;_name, &#8216;*&#8217;)</strong>, as without you will still be getting just the join table fields.</p>
<p>So there you go, it took me quite a bit of fiddling and randomly changing the parameter set to arrive at the final solution. Hope it saves you the hassle too!</p>
<div id="crp_related"><h2>Related Articles:</h2><ul><li><a href="http://think-robot.com/2009/05/doctrine-many-to-many-with-extra-fields/" rel="bookmark">Doctrine Many To Many With Extra Fields</a></li><li><a href="http://think-robot.com/2008/11/wordpress-nextgen-gallery-tweak/" rel="bookmark">Wordpress NextGen gallery tweak</a></li><li><a href="http://think-robot.com/2009/04/week-of-the-month-in-mysql/" rel="bookmark">Week of the Month in Mysql</a></li><li><a href="http://think-robot.com/2009/02/zend-framework-decorators-labels-and-checkboxes/" rel="bookmark">Zend Framework Decorators - Labels and Checkboxes</a></li><li><a href="http://think-robot.com/2008/10/display-meetings-from-entourage-using-geektool/" rel="bookmark">Display Meetings From Entourage Using GeekTool</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://think-robot.com/2009/04/zend_db_select-multiple-table-joins-explained/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Zend Framework Decorators - Labels and Checkboxes</title>
		<link>http://think-robot.com/2009/02/zend-framework-decorators-labels-and-checkboxes/</link>
		<comments>http://think-robot.com/2009/02/zend-framework-decorators-labels-and-checkboxes/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 11:16:12 +0000</pubDate>
		<dc:creator>Joanna</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[forms]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[Zend]]></category>

		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.think-robot.com/?p=20</guid>
		<description><![CDATA[Very often it is the smallest things that annoy us the most. It took me a while to figure out why the placement parameter was not changing anything. I started of with the following:
'decorators' =&#62; array(
	array('Label'),
	array('ViewHelper')
)

Unfortunately switching the order between Label and ViewHelper did not change the order of elements. So I found this parameter [...]]]></description>
			<content:encoded><![CDATA[<p>Very often it is the smallest things that annoy us the most. It took me a while to figure out why the placement parameter was not changing anything. I started of with the following:</p>
<pre><code>'decorators' =&gt; array(
	array('Label'),
	array('ViewHelper')
)</code></pre>
<p><span id="more-20"></span><br />
Unfortunately switching the order between Label and ViewHelper did not change the order of elements. So I found this parameter called &#8220;placement&#8221;.</p>
<pre><code>'decorators' =&gt; array(
	array('Label', array('placement' =&gt; 'APPEND')),
	array('ViewHelper')
)</code></pre>
<p>It can take two values: PREPEND or APPEND. At this point however I did not realize that now the order of Label and ViewHelper did matter. Only the order below will make any difference to the html elements order.</p>
<pre><code>'decorators' =&gt; array(
	array('ViewHelper'),
	array('Label', array('placement' =&gt; 'APPEND'))
)</code></pre>
<p>This finally resulted in the desired effect.</p>
<div id="crp_related"><h2>Related Articles:</h2><ul><li><a href="http://think-robot.com/2009/07/autloading-modular-forms-models-in-zend-framework-18/" rel="bookmark">Autloading modular forms & models in Zend Framework 1.8</a></li><li><a href="http://think-robot.com/2008/11/wordpress-nextgen-gallery-tweak/" rel="bookmark">Wordpress NextGen gallery tweak</a></li><li><a href="http://think-robot.com/2009/04/zend_db_select-multiple-table-joins-explained/" rel="bookmark">Zend_Db_Select multiple table joins explained</a></li><li><a href="http://think-robot.com/2009/05/doctrine-many-to-many-with-extra-fields/" rel="bookmark">Doctrine Many To Many With Extra Fields</a></li><li><a href="http://think-robot.com/2008/12/using-zend_mail-and-google-smtp-to-send-emails/" rel="bookmark">Using Zend_Mail and Google SMTP to send emails</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://think-robot.com/2009/02/zend-framework-decorators-labels-and-checkboxes/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using Zend_Mail and Google SMTP to send emails</title>
		<link>http://think-robot.com/2008/12/using-zend_mail-and-google-smtp-to-send-emails/</link>
		<comments>http://think-robot.com/2008/12/using-zend_mail-and-google-smtp-to-send-emails/#comments</comments>
		<pubDate>Sun, 28 Dec 2008 19:15:11 +0000</pubDate>
		<dc:creator>Joanna</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[emails]]></category>

		<category><![CDATA[Google]]></category>

		<category><![CDATA[smtp]]></category>

		<category><![CDATA[Zend]]></category>

		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.think-robot.com/?p=21</guid>
		<description><![CDATA[You can set this globally, for example in your bootstrap.php file:
$tr = new Zend_Mail_Transport_Smtp('smtp.gmail.com', array(
	'auth' =&#62; 'login',
	'username' =&#62; 'YOUR_USERNAME@gmail.com',
	'password' =&#62; 'YOUR_PASSWORD',
	'ssl' =&#62; 'ssl',
	'port' =&#62; 465)
);
Zend_Mail::setDefaultTransport($tr);

And later just use the normal Zend_Mail function as usual:
$mail = new Zend_Mail();
$mail-&#62;setBodyHtml('Your html email here.');
$mail-&#62;addTo('send_to@mail.com');
$mail-&#62;setSubject('Mail Subject');
$mail-&#62;setFrom('from@mail.com');
$mail-&#62;send();
To quickly explain the settings:
You need to set the authentication type to login, and provide [...]]]></description>
			<content:encoded><![CDATA[<p>You can set this globally, for example in your bootstrap.php file:</p>
<pre><code>$tr = new Zend_Mail_Transport_Smtp('smtp.gmail.com', array(
	'auth' =&gt; 'login',
	'username' =&gt; 'YOUR_USERNAME@gmail.com',
	'password' =&gt; 'YOUR_PASSWORD',
	'ssl' =&gt; 'ssl',
	'port' =&gt; 465)
);
Zend_Mail::setDefaultTransport($tr);</code></pre>
<p><span id="more-21"></span></p>
<p>And later just use the normal Zend_Mail function as usual:</p>
<pre><code>$mail = new Zend_Mail();
$mail-&gt;setBodyHtml('Your html email here.');
$mail-&gt;addTo('send_to@mail.com');
$mail-&gt;setSubject('Mail Subject');
$mail-&gt;setFrom('from@mail.com');
$mail-&gt;send();</code></pre>
<p>To quickly explain the settings:<br />
You need to set the authentication type to login, and provide your Google email and password, as obviously to prevent spam Google needs some verification of who you are. Then we specify the ssl type: Zend supports tls and ssl, and for Google we need to specify the later one. This also means that we need to use port <strong>465</strong> instead of the standard <strong>25</strong>.</p>
<div id="crp_related"><h2>Related Articles:</h2><ul><li><a href="http://think-robot.com/2008/08/server-error-500-htaccess-require-valid-user/" rel="bookmark">Server Error 500 - htaccess require valid-user</a></li><li><a href="http://think-robot.com/2009/05/doctrine-many-to-many-with-extra-fields/" rel="bookmark">Doctrine Many To Many With Extra Fields</a></li><li><a href="http://think-robot.com/2008/10/display-meetings-from-entourage-using-geektool/" rel="bookmark">Display Meetings From Entourage Using GeekTool</a></li><li><a href="http://think-robot.com/2009/07/redirect-in-controller-plugin-zend-framework-18/" rel="bookmark">Redirect in controller plugin - Zend Framework 1.8</a></li><li><a href="http://think-robot.com/2008/08/opensuse-11-on-lenovo-thinkpad-x61-tablet-pc/" rel="bookmark">openSUSE 11 on Lenovo Thinkpad X61 (tablet pc)</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://think-robot.com/2008/12/using-zend_mail-and-google-smtp-to-send-emails/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
