<?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; php</title>
	<atom:link href="http://think-robot.com/tag/php/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>Multiple changes and a delete on same object in doctrine</title>
		<link>http://think-robot.com/2010/03/multiple-changes-and-a-delete-on-same-object-in-doctrine/</link>
		<comments>http://think-robot.com/2010/03/multiple-changes-and-a-delete-on-same-object-in-doctrine/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 20:58:13 +0000</pubDate>
		<dc:creator>Joanna</dc:creator>
		
		<category><![CDATA[Code]]></category>

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

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

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

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

		<guid isPermaLink="false">http://think-robot.com/?p=219</guid>
		<description><![CDATA[If you want to make several different changes to a doctrine record object you might find yourself slightly puzzled when it comes to deleting related objects.
$user['Address']->delete();
$user['Address']->state(Doctrine_Record::STATE_LOCKED);
(...)
$user->save();
It seems that unless you set the state the save later on still sees an initialized (though empty!) relation.
Related Articles:Doctrine Many To Many With Extra FieldsHitch. Object-oriented event handlers with [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to make several different changes to a doctrine record object you might find yourself slightly puzzled when it comes to deleting related objects.</p>
<pre><code><code>$user['Address']->delete();
$user['Address']->state(Doctrine_Record::STATE_LOCKED);
(...)
$user->save();</code></code></pre>
<p>It seems that unless you set the state the save later on still sees an initialized (though empty!) relation.</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/2009/06/hitch-object-oriented-event-handlers-with-jquery/" rel="bookmark">Hitch. Object-oriented event handlers with jQuery</a></li><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/2008/06/atmedia-london-2008/" rel="bookmark">@media - London, 2008</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/2010/03/multiple-changes-and-a-delete-on-same-object-in-doctrine/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Zend_Date time part and GMT</title>
		<link>http://think-robot.com/2009/12/zend_date-time-part-and-gmt/</link>
		<comments>http://think-robot.com/2009/12/zend_date-time-part-and-gmt/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 21:06:04 +0000</pubDate>
		<dc:creator>Joanna</dc:creator>
		
		<category><![CDATA[Articles]]></category>

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

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

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

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

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

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

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

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

		<guid isPermaLink="false">http://think-robot.com/?p=215</guid>
		<description><![CDATA[If you live in the UK you might have a surprise waiting in store for you if you use Zend_Date for the time part only. For a while I even thought this was a bug, however digging deeper has shown that actually it&#8217;s Zend_Date that is right, in a way at least.
When setting a time [...]]]></description>
			<content:encoded><![CDATA[<p>If you live in the UK you might have a surprise waiting in store for you if you use Zend_Date for the time part only. For a while I even thought this was a bug, however digging deeper has shown that actually it&#8217;s Zend_Date that is right, in a way at least.</p>
<p>When setting a time before 1972 - this is 1970 and 1971 the time part will not be shifted in the UK locale as DST was only introduced in 1972!</p>
<p>This means if you are only calculating times and need the appropriate time adjustment you will need to set a date as no date part in Zend_Date means 1st Jan 1970.</p>
<div id="crp_related"><h2>Related Articles:</h2><ul><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/04/week-of-the-month-in-mysql/" rel="bookmark">Week of the Month in Mysql</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><li><a href="http://think-robot.com/2008/12/strong-ownership-list-approach/" rel="bookmark">Strong ownership list approach</a></li><li><a href="http://think-robot.com/2009/04/regex-for-autolinking-urls/" rel="bookmark">Regex for Autolinking URLs</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://think-robot.com/2009/12/zend_date-time-part-and-gmt/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Autloading modular forms &amp; models in Zend Framework 1.8</title>
		<link>http://think-robot.com/2009/07/autloading-modular-forms-models-in-zend-framework-18/</link>
		<comments>http://think-robot.com/2009/07/autloading-modular-forms-models-in-zend-framework-18/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 21:55:00 +0000</pubDate>
		<dc:creator>Joanna</dc:creator>
		
		<category><![CDATA[Code]]></category>

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

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

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

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

		<guid isPermaLink="false">http://think-robot.com/?p=200</guid>
		<description><![CDATA[It&#8217;s not really obvious with the error messages you get, but using a thing like Form_Login does not work out of the box with a modular structure. Which is slightly surprising considering that it&#8217;s inside the default module.
I have found examples like the second one below, but no one mentions that you actually declare the [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s not really obvious with the error messages you get, but using a thing like Form_Login does not work out of the box with a modular structure. Which is slightly surprising considering that it&#8217;s inside the default module.</p>
<p>I have found <a href="http://forums.zend.com/viewtopic.php?f=69&#038;t=1288&#038;start=0" class="external">examples like the second one below</a>, but no one mentions that you actually declare the default namespace too for everything to work.</p>
<pre><code><code>$autoloader = new Zend_Application_Module_Autoloader(array(
	'namespace' => '',
	'basePath'  => APPLICATION_PATH .'/modules/default',
	'resourceTypes' => array (
		'form' => array(
		'path' => 'forms',
		'namespace' => 'Form',
    ),
	'model' => array(
		'path' => 'models',
		'namespace' => 'Model',
    	),
    )
));

$autoloader = new Zend_Application_Module_Autoloader(array(
	'namespace' => 'Admin_',
	'basePath'  => APPLICATION_PATH .'/modules/admin',
	'resourceTypes' => array (
		'form' => array(
		'path' => 'forms',
		'namespace' => 'Form',
    ),
	'model' => array(
		'path' => 'models',
		'namespace' => 'Model',
    	),
    )
));</code></code></pre>
<div id="crp_related"><h2>Related Articles:</h2><ul><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/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/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/12/phpunit-selenium-screenshot-path-problem/" rel="bookmark">PHPUnit & Selenium - screenshot path problem</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://think-robot.com/2009/07/autloading-modular-forms-models-in-zend-framework-18/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Doctrine Many To Many With Extra Fields</title>
		<link>http://think-robot.com/2009/05/doctrine-many-to-many-with-extra-fields/</link>
		<comments>http://think-robot.com/2009/05/doctrine-many-to-many-with-extra-fields/#comments</comments>
		<pubDate>Sat, 09 May 2009 10:25:13 +0000</pubDate>
		<dc:creator>Joanna</dc:creator>
		
		<category><![CDATA[Code]]></category>

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

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

		<category><![CDATA[many to many]]></category>

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

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

		<guid isPermaLink="false">http://think-robot.com/?p=180</guid>
		<description><![CDATA[Recently I have started using Doctrine with Zend Framework. Most of the time it is great, but sometimes I get stuck on this or that issue. Most of my problems so far have been connected with the Many to Many relationship. Here are a few tips I learned the hard way.
Automatic relationship detection
When setting up [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I have started using Doctrine with Zend Framework. Most of the time it is great, but sometimes I get stuck on this or that issue. Most of my problems so far have been connected with the Many to Many relationship. Here are a few tips I learned the hard way.<span id="more-180"></span></p>
<h2>Automatic relationship detection</h2>
<p>When setting up a YAML file with your database schema you can start it with the handy declaration:</p>
<pre><code><code>---
detect_relations: true</code></code></pre>
<p>It does the One to Many relationship for you nicely, however the Many to Many ones did not work out of the box and required manual BaseModel tweaking. Take for example my <strong>Tag</strong>, <strong>Website</strong>, and <strong>WebsiteTag</strong> classes.</p>
<h3>BaseTag:</h3>
<pre><code><code>abstract class BaseTag extends Doctrine_Record {

  public function setTableDefinition() {
    $this-&gt;setTableName('ts_tags');
    $this-&gt;hasColumn('name', 'string', 128, array('type' =&gt; 'string', 'length' =&gt; '128'));
    $this-&gt;hasColumn('is_category as isCategory', 'integer', 1, array('type' =&gt; 'integer', 'length' =&gt; '1'));
    $this-&gt;hasColumn('page_id', 'integer', 8, array('type' =&gt; 'integer', 'length' =&gt; 8));
    $this-&gt;hasColumn('ordering', 'integer', 5, array('type' =&gt; 'integer', 'length' =&gt; '5'));
  }

  public function setUp() {
    $this-&gt;hasOne('Page', array('local' =&gt; 'page_id',
                                              'foreign' =&gt; 'id'));
<strong>
    $this-&gt;hasMany('Website as Websites', array('local' =&gt; 'tag_id',
                                                                     'foreign' =&gt; 'website_id',
                                                                     'refClass' =&gt; 'WebsiteTag'));</strong>

    $i18n0 = new Doctrine_Template_I18n(array('fields' =&gt; array(0 =&gt; 'name')));
    $this-&gt;actAs($i18n0);
  }
}</code></code></pre>
<h3>BaseWebsite:</h3>
<pre><code><code>abstract class BaseWebsite extends Doctrine_Record{
  public function setTableDefinition() {
    $this-&gt;setTableName('ts_websites');
    $this-&gt;hasColumn('page_id', 'integer', 8, array('type' =&gt; 'integer', 'length' =&gt; 8));
    $this-&gt;hasColumn('title', 'string', 128, array('type' =&gt; 'string', 'length' =&gt; '128'));
    $this-&gt;hasColumn('client', 'string', 128, array('type' =&gt; 'string', 'length' =&gt; '128'));
    $this-&gt;hasColumn('link', 'string', 255, array('type' =&gt; 'string', 'length' =&gt; '255'));
    $this-&gt;hasColumn('intro', 'string', null, array('type' =&gt; 'string'));
    $this-&gt;hasColumn('content', 'string', null, array('type' =&gt; 'string'));
    $this-&gt;hasColumn('published', 'timestamp', null, array('type' =&gt; 'timestamp'));
    $this-&gt;hasColumn('is_home as isHome', 'integer', 1, array('type' =&gt; 'integer', 'length' =&gt; '1'));
  }

  public function setUp() {
    $this-&gt;hasOne('Page', array('local' =&gt; 'page_id',
                                              'foreign' =&gt; 'id'));

    <strong>$this-&gt;hasMany('Tag as Tags', array('local' =&gt; 'website_id',
                                                          'foreign' =&gt; 'tag_id',
                                                          'refClass' =&gt; 'WebsiteTag'));</strong>

    $this-&gt;hasMany('Media', array('local' =&gt; 'website_id',
                                                 'foreign' =&gt; 'media_id',
                                                 'refClass' =&gt; 'WebsiteMedia'));

    $i18n0 = new Doctrine_Template_I18n(array('fields' =&gt; array(0 =&gt; 'intro', 1 =&gt; 'content', 2 =&gt; 'title')));
    $this-&gt;actAs($i18n0);
  }
}
</code></code></pre>
<h3>BaseWebsiteTag:</h3>
<pre><code><code>abstract class BaseWebsiteTag extends Doctrine_Record {

  public function setTableDefinition() {
    $this-&gt;setTableName('ts_website_has_tags');
    $this-&gt;hasColumn('tag_id', 'integer', 8, array('type' =&gt; 'integer', 'length' =&gt; 8, <strong>'primary' =&gt; true )</strong>);
    $this-&gt;hasColumn('website_id', 'integer', 8, array('type' =&gt; 'integer', 'length' =&gt; 8,<strong> 'primary' =&gt; true</strong>));
  }

  public function setUp() {
  }
}
</code></code></pre>
<p>The highlighted portions of code needed to be added. You can actually define these manually in the YAML file, the catch is that I was expecting it to happen magically with the auto relationship setting.</p>
<h2>Many to Many with extra fields</h2>
<p>Another little issue that Doctrine has is when you try to retrieve records. It in a way skips the joining table and retrieves a collection of the final items. In most cases this is exactly what you might need. However for my Media I decided to keep the ordering in the joining table - WebsiteMedia.</p>
<pre><code><code>$q = Doctrine_Query::create()
  -&gt;from('Website w')
  -&gt;joinLeft('w.Media');</code></code></pre>
<p>If you simply proceed with the above you only get Media objects without the ordering.</p>
<h3>BaseWebsiteMedia:</h3>
<pre><code><code>abstract class BaseWebsiteMedia extends Doctrine_Record {

    public function setTableDefinition() {
        $this-&gt;setTableName('ts_website_has_media');
        $this-&gt;hasColumn('website_id', 'integer', 8, array('type' =&gt; 'integer', 'length' =&gt; 8, 'primary' =&gt; true));
        $this-&gt;hasColumn('media_id', 'integer', 8, array('type' =&gt; 'integer', 'length' =&gt; 8, 'primary' =&gt; true));
        $this-&gt;hasColumn('caption', 'string', 255, array('type' =&gt; 'string', 'length' =&gt; '255'));
        $this-&gt;hasColumn('is_main as isMain', 'integer', 1, array('type' =&gt; 'integer', 'length' =&gt; '1'));
        $this-&gt;hasColumn('ordering', 'integer', 4, array('type' =&gt; 'integer', 'length' =&gt; '4'));
    }

    public function setUp() {
        <strong>$this-&gt;hasOne('Website', array('local' =&gt; 'website_id',
                                       'foreign' =&gt; 'id'));

        $this-&gt;hasOne('Media', array('local' =&gt; 'media_id',
                                     'foreign' =&gt; 'id'));</strong>

        $i18n0 = new Doctrine_Template_I18n(array('fields' =&gt; array(0 =&gt; 'caption')));
        $this-&gt;actAs($i18n0);
    }
}</code></code></pre>
<p>If you do not have the additional One to Many relations declared already you should add them now. With the modified model now you can get the records like so:</p>
<pre><code><code>$q = Doctrine_Query::create()
  ->from('Website w')
  ->leftJoin('w.WebsiteMedia wm')
    ->leftJoin('wm.Media m');
</code></code></pre>
<p>This gives you a collection of WebsiteMedia records each containing the actual Media item.</p>
<div id="crp_related"><h2>Related Articles:</h2><ul><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/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/12/using-zend_mail-and-google-smtp-to-send-emails/" rel="bookmark">Using Zend_Mail and Google SMTP to send emails</a></li><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></ul></div>]]></content:encoded>
			<wfw:commentRss>http://think-robot.com/2009/05/doctrine-many-to-many-with-extra-fields/feed/</wfw:commentRss>
		</item>
		<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>Regex for Autolinking URLs</title>
		<link>http://think-robot.com/2009/04/regex-for-autolinking-urls/</link>
		<comments>http://think-robot.com/2009/04/regex-for-autolinking-urls/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 12:04:42 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
		
		<category><![CDATA[Code]]></category>

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

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

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

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

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

		<guid isPermaLink="false">http://think-robot.com/?p=145</guid>
		<description><![CDATA[For a recent project I was wanting to perform an exceptionally common task. Converting things that look like URLs in the text into clickable links. However wherever I&#8217;ve seen this implemented before I&#8217;ve always encountered the same annoying problem, namely the links break when the user types a URL and adds some punctuation at the [...]]]></description>
			<content:encoded><![CDATA[<p>For a recent project I was wanting to perform an exceptionally common task. Converting things that look like URLs in the text into clickable links. However wherever I&#8217;ve seen this implemented before I&#8217;ve always encountered the same annoying problem, namely the links break when the user types a URL and adds some punctuation at the end since the punctuation gets captured as part of the link.</p>
<p><span id="more-145"></span></p>
<p><strong>For example:</strong></p>
<p><em>If you like the Seattle Mariners and enjoy learning about baseball statistics you should really visit </em><strong><em>http://ussmariner.com.</em></strong></p>
<p>It struck me that this should be something that would be solvable with <a href="http://www.regular-expressions.info/lookaround.html">Lookahead</a>, that is we could check whether the punctuation character was followed directly by a character that could be part of the URL.</p>
<p>The following regex attempts to do this. It will allow . , ! ? ; and : to appear at the end of a URL without including them in the match.</p>
<pre><code><code>$str = preg_replace('%(https?://(([^ .,!?;:"\'\(\)\r\n\t])|((\.|,|!|\?|;|:)(?=[_a-z0-9])))+)%i', '&lt;a href="\\1"&gt;\\1&lt;/a&gt;', $str);</code></code></pre>
<p>It works using an <a href="http://www.regular-expressions.info/alternation.html" target="_blank">alternation</a>. The first side of the alternation checks for any character that isn&#8217;t in our punctuation list (and certain other characters such as quote marks and spaces that we simply don&#8217;t want to allow in a URL). The other half checks the characters in the punctuation list and uses lookahead to ensure that they&#8217;re followed by another character.</p>
<p>I&#8217;m sure there&#8217;s room for improvement here, but I&#8217;ve been pretty please with how this has worked so far.</p>
<div id="crp_related"><h2>Related Articles:</h2><ul><li><a href="http://think-robot.com/2008/11/nested-sortable-using-jtree-clickable-links/" rel="bookmark">Nested sortable using jTree - clickable links</a></li><li><a href="http://think-robot.com/2009/02/how-to-use-the-strong-ownership-list/" rel="bookmark">How To Use the Strong Ownership List</a></li><li><a href="http://think-robot.com/2008/12/strong-ownership-list-approach/" rel="bookmark">Strong ownership list approach</a></li><li><a href="http://think-robot.com/2009/12/zend_date-time-part-and-gmt/" rel="bookmark">Zend_Date time part and GMT</a></li><li><a href="http://think-robot.com/2009/02/firefox-ignores-tabs-but-not-spaces-in-a-pre-tag/" rel="bookmark">Firefox ignores tabs but not spaces in a pre tag</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://think-robot.com/2009/04/regex-for-autolinking-urls/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>How to convert PDT projects into PHPEclipse projects</title>
		<link>http://think-robot.com/2008/10/how-to-convert-pdt-projects-into-phpeclipse-projects/</link>
		<comments>http://think-robot.com/2008/10/how-to-convert-pdt-projects-into-phpeclipse-projects/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 10:12:56 +0000</pubDate>
		<dc:creator>Joanna</dc:creator>
		
		<category><![CDATA[Tutorials]]></category>

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

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

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

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

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

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

		<guid isPermaLink="false">http://www.think-robot.com/?p=14</guid>
		<description><![CDATA[If for some reason you decide to swap from one Eclipse based PHP IDE to another, rather than recreate the projects you can change their association, so that the project builders work correctly.
This is basically what you need to do if you get the following error when trying to ctrl clicka function:
&#8220;The resource is not [...]]]></description>
			<content:encoded><![CDATA[<p>If for some reason you decide to swap from one Eclipse based PHP IDE to another, rather than recreate the projects you can change their association, so that the project builders work correctly.</p>
<p>This is basically what you need to do if you get the following error when trying to ctrl clicka function:</p>
<p><strong>&#8220;The resource is not on the build path of a PHP project&#8221;</strong></p>
<p>To convert to a PHPEclipse compatible project you basically need to replace the buildSpec and natures sections of the<strong> .project</strong> file with the following:</p>
<pre><code>&lt;buildSpec&gt;
	&lt;buildCommand&gt;
		&lt;name&gt;net.sourceforge.phpeclipse.parserbuilder&lt;/name&gt;
		&lt;arguments&gt;
		&lt;/arguments&gt;
	&lt;/buildCommand&gt;
&lt;/buildSpec&gt;
&lt;natures&gt;
	&lt;nature&gt;net.sourceforge.phpeclipse.phpnature&lt;/nature&gt;
&lt;/natures&gt;</code></pre>
<p>If you need to convert the other way, or to something else, simply grab the appropriate section from a working project and paste it into the<strong> .project</strong> file you need to fix.</p>
<div id="crp_related"><h2>Related Articles:</h2><ul><li><a href="http://think-robot.com/2008/12/strong-ownership-list-approach/" rel="bookmark">Strong ownership list approach</a></li><li><a href="http://think-robot.com/2009/02/how-to-use-the-strong-ownership-list/" rel="bookmark">How To Use the Strong Ownership List</a></li><li><a href="http://think-robot.com/2008/11/nested-sortable-using-jtree-clickable-links/" rel="bookmark">Nested sortable using jTree - clickable links</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/2008/11/wordpress-nextgen-gallery-tweak/" rel="bookmark">Wordpress NextGen gallery tweak</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://think-robot.com/2008/10/how-to-convert-pdt-projects-into-phpeclipse-projects/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to use special characters in FPDF</title>
		<link>http://think-robot.com/2008/09/how-to-use-special-characters-in-fpdf/</link>
		<comments>http://think-robot.com/2008/09/how-to-use-special-characters-in-fpdf/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 12:45:49 +0000</pubDate>
		<dc:creator>Joanna</dc:creator>
		
		<category><![CDATA[Code]]></category>

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

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

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

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

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

		<guid isPermaLink="false">http://www.think-robot.com/?p=12</guid>
		<description><![CDATA[FPDF is a nice little library for php that allows you to create PDFs on the fly. It&#8217;s great for all sorts of document, amongs them invoices. Until you try to use say a pound (£) or euro (€) sign. Basically the library itself does not support utf-8, so the moment you need to insert [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.fpdf.org" target="_blank">FPDF</a> is a nice little library for php that allows you to create PDFs on the fly. It&#8217;s great for all sorts of document, amongs them invoices. Until you try to use say a pound (£) or euro (€) sign. Basically the library itself does not support utf-8, so the moment you need to insert anything extra into your document a conversion needs to be done.</p>
<p>To save you some searching and a masive panic attack here is the easy way to do it:</p>
<pre><code>iconv("UTF-8", "ISO-8859-1", "£");</code></pre>
<p>You could also use the same command to do the whole text rather than just the pound sign itself.  Example below:<br />
<span id="more-12"></span><br />
You can use the iconv function at any point, however probably the easiest solution is to put it inside functions of the class you use to extend FPDF:</p>
<pre><code>class myPdf extends FPDF {
    [...]
    public function showMoney($money){
        $this-&gt;cell(10,10,<strong>iconv("UTF-8", "ISO-8859-1", "£").</strong> $money,0);
    }
}</code></pre>
<div id="crp_related"><h2>Related Articles:</h2><ul><li><a href="http://think-robot.com/2008/11/nested-sortable-using-jtree-clickable-links/" rel="bookmark">Nested sortable using jTree - clickable links</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/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/2008/11/wordpress-nextgen-gallery-tweak/" rel="bookmark">Wordpress NextGen gallery tweak</a></li><li><a href="http://think-robot.com/2009/02/how-to-use-the-strong-ownership-list/" rel="bookmark">How To Use the Strong Ownership List</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://think-robot.com/2008/09/how-to-use-special-characters-in-fpdf/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
