<?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>On Tech and Software &#187; PHP</title>
	<atom:link href="http://jmgtan.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://jmgtan.com</link>
	<description>Random thoughts on technology, ventures, algorithms, frameworks, gadgets and THE MAN</description>
	<lastBuildDate>Fri, 02 Jul 2010 11:14:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Upgrading to Symfony 1.4 from PEAR based 1.2</title>
		<link>http://jmgtan.com/2010/01/03/upgrading-to-symfony-1-4-from-pear-based-1-2/</link>
		<comments>http://jmgtan.com/2010/01/03/upgrading-to-symfony-1-4-from-pear-based-1-2/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 02:26:45 +0000</pubDate>
		<dc:creator>Jan Michael Tan</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://jmgtan.com/?p=199</guid>
		<description><![CDATA[I&#8217;ve been working on a project, which started on 1.2.7, for almost 6 months now and have been upgrading it religiously along the 1.2.x branch which stopped at 1.2.10. We&#8217;re currently entering the testing stage, and being as curious as I am opted to create a 1.4 branch from the current trunk and started the [...]]]></description>
			<content:encoded><![CDATA[<p></p>
<p>I&#8217;ve been working on a project, which started on 1.2.7, for almost 6 months now and have been upgrading it religiously along the 1.2.x branch which stopped at 1.2.10. We&#8217;re currently entering the testing stage, and being as curious as I am opted to create a 1.4 branch from the current trunk and started the upgrade process while merging fixes from the trunk as fixes come in. We&#8217;re using the PEAR-based approach which allows us to quickly upgrade the base installation as soon as a new release comes in. Although i&#8217;m planning to migrate it to the subversion approach soon, but thats another blog post.</p>
<p><span id="more-199"></span></p>
<p>So lets start with the upgrade, symfony 1.4 and 1.3 is basically the same feature-wised but the former lacks the backwards compatibility that the latter provides, basically 1.3 is just a stepping stone to upgrade to 1.4. The Symfony team really did a great job on the seamless upgrade process. Also to have a better background on the upgrade process read the upgrade document from their website (<a href="http://www.symfony-project.org/tutorial/1_4/en/upgrade" target="_blank">http://www.symfony-project.org/tutorial/1_4/en/upgrade</a>). Ok, so lets start with the upgrade.</p>
<p>Lets uninstall symfony 1.2</p>
<pre class="brush: bash;">

pear uninstall symfony/symfony
</pre>
<p>Then install symfony 1.3</p>
<pre class="brush: bash;">

pear install symfony/symfony-1.3.1
</pre>
<p>Once installed, make sure to upgrade the plugins, rebuild the models, and clear the cache to make sure you&#8217;re using the new files. Now you can opt to continue upgrading to 1.4 and drop the backwards compatibility or just stick with 1.3 for the time being, both of which are being supported but 1.4 is a LTS release, meaning that it has a longer support period than 1.3. Before upgrading to 1.4 it is important to remove old class files, symfony provides a build-in task to ease the transition. Just execute this command and symfony will list down all of the deprecated stuff that should be remove/modified, they also provided documentation on what to replace the deprecated stuff with (<a href="http://www.symfony-project.org/tutorial/1_4/en/deprecated" target="_blank">http://www.symfony-project.org/tutorial/1_4/en/deprecated</a>)</p>
<pre class="brush: bash;">

symfony project:validate
</pre>
<p>So now that you&#8217;ve removed/modified all of the deprecated stuff, upgrading is quite similar to 1.3.</p>
<p>Remove the old symfony installation</p>
<pre class="brush: bash;">

pear uninstall symfony/symfony
</pre>
<p>Install the new one</p>
<pre class="brush: bash;">

pear install symfony/symfony-1.4.1
</pre>
<p>Then just clear the cache. Also the freeze/unfreeze task has been removed in 1.4; it may or may not be important to you but I use it when deploying to our servers, one quick fix is to just create a lib/vendor folder and copy/paste the symfony folder found in your PEAR installation folder, and then modifying the include call in the config/ProjectConfiguration.class.php file. So now you have a easily upgradable and independent symfony installation inside your app.</p>
<p></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fjmgtan.com%2F2010%2F01%2F03%2Fupgrading-to-symfony-1-4-from-pear-based-1-2%2F&amp;linkname=Upgrading%20to%20Symfony%201.4%20from%20PEAR%20based%201.2"><img src="http://jmgtan.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jmgtan.com/2010/01/03/upgrading-to-symfony-1-4-from-pear-based-1-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Symfony Doctrine or Propel</title>
		<link>http://jmgtan.com/2009/09/10/symfony-doctrine-or-propel/</link>
		<comments>http://jmgtan.com/2009/09/10/symfony-doctrine-or-propel/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 12:22:08 +0000</pubDate>
		<dc:creator>Jan Michael Tan</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://jmgtan.com/?p=173</guid>
		<description><![CDATA[Been giving this alot of thought lately. What to use for my next project. Ever since symfony 1.2&#8242;s move to Propel 1.3, the major argument of speed against Propel has been solved with its migration out of creole and into PDO. So speed is definitely at par with Doctrine, but the curious side of me [...]]]></description>
			<content:encoded><![CDATA[<p></p>
<p>Been giving this alot of thought lately. What to use for my next project. Ever since symfony 1.2&#8242;s move to Propel 1.3, the major argument of speed against Propel has been solved with its migration out of creole and into PDO. So speed is definitely at par with Doctrine, but the curious side of me wishes to delve into something new to mix things up a bit.</p>
<p>What to use? Doctrine or Propel?</p>
<p></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fjmgtan.com%2F2009%2F09%2F10%2Fsymfony-doctrine-or-propel%2F&amp;linkname=Symfony%20Doctrine%20or%20Propel"><img src="http://jmgtan.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jmgtan.com/2009/09/10/symfony-doctrine-or-propel/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Symfony Forms Tutorial: Quick Registration Form</title>
		<link>http://jmgtan.com/2009/07/09/symfony-forms-tutorial-quick-registration-form/</link>
		<comments>http://jmgtan.com/2009/07/09/symfony-forms-tutorial-quick-registration-form/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 09:27:23 +0000</pubDate>
		<dc:creator>Jan Michael Tan</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://jmgtan.com/?p=148</guid>
		<description><![CDATA[I was initially skeptical about these numerous form frameworks that are coming out, I would initially opt to create forms and validations the old fashion way, but after giving symfony forms a shot; I can honestly say i&#8217;m converted! Lets start the tutorial by creating a basic registration form with a captcha. I would assume [...]]]></description>
			<content:encoded><![CDATA[<p></p>
<p>I was initially skeptical about these numerous form frameworks that are coming out, I would initially opt to create forms and validations the old fashion way, but after giving symfony forms a shot; I can honestly say i&#8217;m converted! Lets start the tutorial by creating a basic registration form with a captcha. I would assume you know the basics of symfony if not go to their website (<a title="Symfony" href="http://www.symfony-project.org" target="_blank">http://www.symfony-project.org</a>) and check out their tutorial.</p>
<p><span id="more-148"></span></p>
<p>After setting up the project, app and modules we will install the plugin sfFormExtraPlugin so we can use ReCaptcha:</p>
<pre class="brush: bash;">
symfony plugin:install sfFormExtraPlugin
</pre>
<p>After that, go to <a title="ReCaptcha" href="http://www.recaptcha.net" target="_blank">http://www.recaptcha.net</a> and register to acquire a public and private key; we&#8217;ll use that later. Now lets start creating the form class</p>
<pre class="brush: php;">
class RegistrationForm extends sfForm {
const PUBLIC_KEY = 'PASTE YOUR PUBLIC KEY FROM RECAPTCHA';
const PRIVATE_KEY = 'PASTE YOUR PRIVATE KEY FROM RECAPTCHA';

public function configure() {
$this-&gt;setWidgets(array(
'username'=&gt;new sfWidgetFormInput(array(), array('size'=&gt;32)),
'password'=&gt;new sfWidgetFormInputPassword(array(), array('size'=&gt;32)),
'confirm_password'=&gt;new sfWidgetFormInputPassword(array(), array('size'=32)),
'email'=&gt;new sfWidgetFormInput(array(), array('size'=&gt;32)),
'captcha'=&gt;new sfWidgetFormReCaptcha(array(
'public_key'=&gt;self::PUBLIC_KEY
))
));

$this-&gt;widgetSchema-&gt;setNameFormat('register[%s]'); //this acts as a namespace and also will be use later for binding POST

$this-&gt;setValidators(array(
'username'=&gt;new sfValidatorString(array('max_length'=&gt;50), array('max_length'=&gt;'Max length of username is 50')),
'password'=&gt;new sfValidatorString(),
'confirm_password'=&gt;new sfValidatorString(),
'email'=&gt;new sfValidatorEmail(),
'captcha'=&gt;new sfValidatorReCaptcha(array('private_key' =&gt; self::PRIVATE_KEY), array('captcha' =&gt; 'Didn\'t match captcha'))
));

$this-&gt;validatorSchema-&gt;setPostValidator(new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::EQUAL, 'confirm_password', array(), array('invalid' =&gt; 'Passwords do not match')));

$this-&gt;widgetSchema-&gt;setLabels(array(
'username'=&gt;'Username',
'password'=&gt;'Password',
'confirm_password'=&gt;'Confirm Password',
'email'=&gt;'Email Address',
'captcha'=&gt;'Captcha'
));
}
}
</pre>
<p>The code in your actions.class.php would be as follows</p>
<pre class="brush: php;">
public function executeRegister(sfWebRequest $r) {
$this-&gt;form = new RegistrationForm();
if($r-&gt;isMethod('post')) {
$captcha = array(
'recaptcha_challenge_field' =&gt; $request-&gt;getParameter('recaptcha_challenge_field'),
'recaptcha_response_field'  =&gt; $request-&gt;getParameter('recaptcha_response_field'),
);

$this-&gt;form-&gt;bind(array_merge($request-&gt;getParameter('register'), array('captcha' =&gt; $captcha)));
if($this-&gt;form-&gt;isValid()) {
$values = $this-&gt;form-&gt;getValues(); //associative array of values
//you can access the POST data like $values['username'] or $values['email']
//do database insertion or other processsing here
}
}
}
</pre>
<p>And lastly displaying the form in your corresponding template would be as follows</p>
<pre class="brush: php;">
&amp;lt;?php echo $form ?&gt;
</pre>
<p>In the next article, we would be discussing how to customize your form layout.</p>
<p></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fjmgtan.com%2F2009%2F07%2F09%2Fsymfony-forms-tutorial-quick-registration-form%2F&amp;linkname=Symfony%20Forms%20Tutorial%3A%20Quick%20Registration%20Form"><img src="http://jmgtan.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jmgtan.com/2009/07/09/symfony-forms-tutorial-quick-registration-form/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Hands on Usage of ZF 1.8.x</title>
		<link>http://jmgtan.com/2009/05/13/hands-on-usage-of-zf-18x/</link>
		<comments>http://jmgtan.com/2009/05/13/hands-on-usage-of-zf-18x/#comments</comments>
		<pubDate>Thu, 14 May 2009 02:38:25 +0000</pubDate>
		<dc:creator>Jan Michael Tan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[zendframework]]></category>

		<guid isPermaLink="false">http://jmgtan.com/?p=141</guid>
		<description><![CDATA[Well that was fast, new maintenance release of Zend Framework is now out! Checking out the changelog, noticed this little gem: Addition of module generation capabilities to Zend_Tool; I posted about that in my initial thoughts of ZF 1.8 post. I started using 1.8 on a new project recently, while actual hands-on usage of the [...]]]></description>
			<content:encoded><![CDATA[<p></p>
<p>Well that was fast, new maintenance release of Zend Framework is now out! Checking out the changelog, noticed this little gem: <strong>Addition of module generation capabilities to Zend_Tool</strong>; I posted about that in <a href="http://jmgtan.com/2009/05/12/thoughts-on-the-new-zend-framework-18/">my initial thoughts of ZF 1.8 post</a>.</p>
<p><span id="more-141"></span></p>
<p>I started using 1.8 on a new project recently, while actual hands-on usage of the new stuff (<em>Zend_Application</em>, <em>Zend_Tool</em>) and the documentations are great, there are still some confusion with regards to how the <em>Resource Autoloader </em>works, there are some conflict with the quick-start tutorial from Zend and the actual reference documentation. According to the documentation, <em>Resource Autoloader </em>should work automatically when using <em>Zend_Application</em>, but according to the quick-start tutorial, you have to initialize it in the <em>Bootstrap</em>. Maybe i&#8217;m missing something, but I&#8217;ve decided to go with the quick-start tutorial for the time being since it works. I&#8217;ve also noticed that there are some new view helpers like ($this-&gt;cycle for one) minor stuff but very helpful!</p>
<p>Using Zend_Form is still an exercise in frustration, especially the decorators. I love the way <em>symfony </em>handles the form layouts, it just passes the form object as an array to the view layer and gets out of the way, allowing designers to actually do the form design. Zend_Form just seems counter-intuitive. They got majority of the stuff correct, but laying out the forms to display how you want them is very hard. Let the view layer handle the layout stuff, allowing the Form object to be more flexible and reusable.</p>
<p></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fjmgtan.com%2F2009%2F05%2F13%2Fhands-on-usage-of-zf-18x%2F&amp;linkname=Hands%20on%20Usage%20of%20ZF%201.8.x"><img src="http://jmgtan.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jmgtan.com/2009/05/13/hands-on-usage-of-zf-18x/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Thoughts on the new Zend Framework 1.8</title>
		<link>http://jmgtan.com/2009/05/12/thoughts-on-the-new-zend-framework-18/</link>
		<comments>http://jmgtan.com/2009/05/12/thoughts-on-the-new-zend-framework-18/#comments</comments>
		<pubDate>Tue, 12 May 2009 07:57:59 +0000</pubDate>
		<dc:creator>Jan Michael Tan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[zendframework]]></category>

		<guid isPermaLink="false">http://jmgtan.com/?p=127</guid>
		<description><![CDATA[Been playing around with the new version of Zend Framework (1.8). The command line Zend_Tools has alot of potential and is very useful for newbies, but still lacks a lot of functionality (support for modules in the command line would be pretty cool!). I loved the Application/Bootstrap approach this puts a lot of much needed [...]]]></description>
			<content:encoded><![CDATA[<p></p>
<p>Been playing around with the new version of Zend Framework (1.8). The command line Zend_Tools has alot of potential and is very useful for newbies, but still lacks a lot of functionality (support for modules in the command line would be pretty cool!). I loved the Application/Bootstrap approach this puts a lot of much needed structure to a very flexible framework. It also centralizes plugins to the front controller and of course custom initializations using _init methods in the Bootstrap file. Although missing in the reference documentation are examples when using a more modular approach when using the Zend_Application.</p>
<p><span id="more-127"></span></p>
<p>Also the quick-start tutorial from Zend&#8217;s website has been updated! It includes a very nice approach to models (much needed overhaul in the next version of ZF). Overall a very solid release from the community. Looking forward to using it in new projects.</p>
<p></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fjmgtan.com%2F2009%2F05%2F12%2Fthoughts-on-the-new-zend-framework-18%2F&amp;linkname=Thoughts%20on%20the%20new%20Zend%20Framework%201.8"><img src="http://jmgtan.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jmgtan.com/2009/05/12/thoughts-on-the-new-zend-framework-18/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Zend Framework Model Based Validation Part 1</title>
		<link>http://jmgtan.com/2008/10/24/zend-framework-model-based-validation-part-1/</link>
		<comments>http://jmgtan.com/2008/10/24/zend-framework-model-based-validation-part-1/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 13:56:35 +0000</pubDate>
		<dc:creator>Jan Michael Tan</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://jmgtan.com/?p=62</guid>
		<description><![CDATA[I&#8217;m not really a big fan of Zend_Form, too verbose and less flexible. I&#8217;ve been using this little base class for several of my freelance projects. It basically allows you to define validation rules for your model&#8217;s columns. This is a very basic version that I&#8217;m planning to enhance soon with custom validation functions. Download [...]]]></description>
			<content:encoded><![CDATA[<p></p>
<p>I&#8217;m not really a big fan of Zend_Form, too verbose and less flexible. I&#8217;ve been using this little base class for several of my freelance projects. It basically allows you to define validation rules for your model&#8217;s columns. This is a very basic version that I&#8217;m planning to enhance soon with custom validation functions.</p>
<p><a href="http://jmgtan.com/files/ZF-ModelBased-Validation-0.1.zip">Download version 0.1</a></p>
<p><strong>USAGE EXAMPLE</strong></p>
<p>Model</p>
<pre class="brush: php;">
&lt;?
class User extends AbstractModelValidator {
	protected $_name = 'users';
	protected $_primary = 'id';
	protected $_rules = array(
		array('name'=&gt;'firstname', 'class'=&gt;'NotEmpty', 'message'=&gt;'Required Field (Firstname)'),
		array('name'=&gt;'firstname', 'class'=&gt;'StringLength', 'options'=&gt;array(0, 50),'message'=&gt;'Max length is 50 (Firstname)'),
		array('name'=&gt;'lastname', 'class'=&gt;'NotEmpty', 'message'=&gt;'Required Field (Lastname)'),
		array('name'=&gt;'lastname', 'class'=&gt;'StringLength', 'options'=&gt;array(0, 50),'message'=&gt;'Max length is 50 (Lastname)'),
	);
}
</pre>
<p>Controller</p>
<pre class="brush: php;">
&lt;?
class UsersController extends Zend_Controller_Action {
	public function addAction() {
		$this-&gt;view-&gt;req = $this-&gt;_request;
		if($this-&gt;_request-&gt;isPost()) {
			$u = new User();
			if($u-&gt;isValid($this-&gt;_request-&gt;getParams())) {

			}
			else {
				$this-&gt;view-&gt;errors = $u-&gt;getValidationMessages();
			}
		}
	}
}
</pre>
<p>View</p>
<pre class="brush: php;">
&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;Add User&lt;/title&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;? if(isset($this-&gt;errors) &amp;&amp; sizeof($this-&gt;errors) &gt; 0): ?&gt;
			&lt;ul&gt;
				&lt;? foreach($this-&gt;errors as $e): ?&gt;
					&lt;li&gt;&lt;?=$e?&gt;&lt;/li&gt;
				&lt;? endforeach; ?&gt;
			&lt;/ul&gt;
		&lt;? endif; ?&gt;
		&lt;div&gt;
			&lt;form action=&quot;&lt;?=$this-&gt;url()?&gt;&quot; method=&quot;post&quot;&gt;
				&lt;div&gt;Firstname:&lt;/div&gt;
				&lt;div&gt;&lt;?=$this-&gt;formText('firstname', $this-&gt;req-&gt;getParam('firstname'), array('size'=&gt;20))?&gt;&lt;/div&gt;
				&lt;div&gt;Lastname::&lt;/div&gt;
				&lt;div&gt;&lt;?=$this-&gt;formText('lastname', $this-&gt;req-&gt;getParam('lastname'), array('size'=&gt;20))?&gt;&lt;/div&gt;
				&lt;div&gt;&lt;?=$this-&gt;formSubmit('submit', 'Submit')?&gt;&lt;/div&gt;
			&lt;/form&gt;
		&lt;/div&gt;
	&lt;/body&gt;
&lt;/html&gt;
</pre>
<p></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fjmgtan.com%2F2008%2F10%2F24%2Fzend-framework-model-based-validation-part-1%2F&amp;linkname=Zend%20Framework%20Model%20Based%20Validation%20Part%201"><img src="http://jmgtan.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jmgtan.com/2008/10/24/zend-framework-model-based-validation-part-1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Simple Pagination</title>
		<link>http://jmgtan.com/2008/09/24/simple-pagination/</link>
		<comments>http://jmgtan.com/2008/09/24/simple-pagination/#comments</comments>
		<pubDate>Thu, 25 Sep 2008 03:42:19 +0000</pubDate>
		<dc:creator>Jan Michael Tan</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://jmgtan.com/?p=41</guid>
		<description><![CDATA[I use alot of Zend Framework for my freelance projects and prior to version 1.6 they have no pagination class to do the dirty work. I know what you&#8217;re thinking right now, why didn&#8217;t I just reused some of the many pagination scripts in the internet and/or in PEAR. I just really needed something simple [...]]]></description>
			<content:encoded><![CDATA[<p></p>
<p>I use alot of Zend Framework for my freelance projects and prior to version 1.6 they have no pagination class to do the dirty work. I know what you&#8217;re thinking right now, why didn&#8217;t I just reused some of the many pagination scripts in the internet and/or in PEAR. I just really needed something simple that I can quickly reuse all over my web-app and here it is</p>
<p>To get the offset for your sql query just do this:</p>
<pre class="brush: php;">
$offset = $numOfItemsPerPage * ($page - 1);
</pre>
<p>Here&#8217;s the code for the pagination, take note that the logic can be use regardless of the programming language, i&#8217;ve also use this in some of my java webapps</p>
<pre class="brush: php;">
&lt;?php
class Paginator {
	const NUM_TRAIL_LEAD_LINKS = 5;

	public static function generate($url, $total, $current = 1, $numPerPage = 5, $var = 'page', $separator = ' ') {
		$totalNumberOfPages = ceil($total / $numPerPage);

		$linksArray = array();
		$isFirstLinkDone = false;
		$i = 1;
		if(($current - self::NUM_TRAIL_LEAD_LINKS) &gt; $i) {
			$i = $current - self::NUM_TRAIL_LEAD_LINKS;
		}

		for(;$i&lt;=$totalNumberOfPages;$i++) {
			if(!$isFirstLinkDone &amp;&amp; $current &gt; 1) {
				$linksArray[] = '&lt;a href=&quot;'.$url.'/'.$var.'/1&quot;&gt;First&lt;/a&gt;';
				$linksArray[] = '&lt;a href=&quot;'.$url.'/'.$var.'/'.($current-1).'&quot;&gt;Prev&lt;/a&gt;';
				$isFirstLinkDone = true;
			}

			if($i == $current) {
				$linksArray[] = '&lt;span style=&quot;font-weight:bold&quot;&gt;'.$current.'&lt;/span&gt;';
			}
			else {
				if(($current + self::NUM_TRAIL_LEAD_LINKS) &lt; $i) {
					break;
				}

				$linksArray[] = '&lt;a href=&quot;'.$url.'/'.$var.'/'.$i.'&quot;&gt;'.$i.'&lt;/a&gt;';
			}
		}

		if($current &lt; $totalNumberOfPages) {
			$linksArray[] = '&lt;a href=&quot;'.$url.'/'.$var.'/'.($current+1).'&quot;&gt;Next&lt;/a&gt;';
			$linksArray[] = '&lt;a href=&quot;'.$url.'/'.$var.'/'.$totalNumberOfPages.'&quot;&gt;Last&lt;/a&gt;';
		}
		return implode($separator, $linksArray);
	}
}
</pre>
<p></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fjmgtan.com%2F2008%2F09%2F24%2Fsimple-pagination%2F&amp;linkname=Simple%20Pagination"><img src="http://jmgtan.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jmgtan.com/2008/09/24/simple-pagination/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Oh no its PHP!!!</title>
		<link>http://jmgtan.com/2008/08/23/oh-no-its-php/</link>
		<comments>http://jmgtan.com/2008/08/23/oh-no-its-php/#comments</comments>
		<pubDate>Sun, 24 Aug 2008 03:03:01 +0000</pubDate>
		<dc:creator>Jan Michael Tan</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[enterprise]]></category>
		<category><![CDATA[opinion]]></category>

		<guid isPermaLink="false">http://jmgtan.com/?p=13</guid>
		<description><![CDATA[A few months ago I was doing some job hunting and i&#8217;ve come across some interesting job interviews in the process. Now I have a good mixture of full-time work and freelance work, and most of my freelance work consists of enterprise PHP web applications; while my full-time work primarily consists of J2EE and Oracle. [...]]]></description>
			<content:encoded><![CDATA[<p></p>
<p>A few months ago I was doing some job hunting and i&#8217;ve come across some interesting job interviews in the process. Now I have a good mixture of full-time work and freelance work, and most of my freelance work consists of enterprise PHP web applications; while my full-time work primarily consists of J2EE and Oracle.</p>
<p>During the course of the interview when they are finished asking me the standard questions regarding my J2EE and Oracle experience, they focused their attention on my freelance works. I must say there is a really big ignorance with the LAMP stack in the enterprise world, opinions and questions that PHP is only a toy language and it cannot &#8220;scale&#8221; like their &#8220;100 concurrent users or the app server will choke&#8221; J2EE apps.  Now this opinions are nothing new, but it&#8217;s hilarious when you actually meet people with that opinion. If only they knew that sites like Digg, Facebook, Friendster were constructed with PHP albeit the web-part only, but like they say, right tools for the right job. I cringe everytime people construct simple intranet sites with full blown J2EE architecture thinking it would automatically scale because it&#8217;s Java/Oracle; apps that could have been simply done with a LAMP stack and 1 week.</p>
<p></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fjmgtan.com%2F2008%2F08%2F23%2Foh-no-its-php%2F&amp;linkname=Oh%20no%20its%20PHP%21%21%21"><img src="http://jmgtan.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jmgtan.com/2008/08/23/oh-no-its-php/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
