<?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>Quality Coding</title>
	<atom:link href="http://blog.gemcoders.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.gemcoders.com</link>
	<description></description>
	<lastBuildDate>Wed, 02 Nov 2011 23:13:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Ruby 1.9.2 installation from source on Ubuntu</title>
		<link>http://blog.gemcoders.com/2011/09/12/ruby-1-9-2-installation-from-source/</link>
		<comments>http://blog.gemcoders.com/2011/09/12/ruby-1-9-2-installation-from-source/#comments</comments>
		<pubDate>Mon, 12 Sep 2011 00:16:58 +0000</pubDate>
		<dc:creator>Pawel Barcik</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby 1.9.2]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog.gemcoders.com/?p=95</guid>
		<description><![CDATA[There are easier ways to install most up to date version of Ruby on your system , for e.g. RVM or rbenv but if you want to have full control over what are you installing because it will be your production system, then this post will show you how to do this. To install Ruby [...]]]></description>
			<content:encoded><![CDATA[<p>There are easier ways to install most up to date version of Ruby on your system , for e.g. <a href="http://beginrescueend.com/" target="_blank">RVM</a> or <a href="https://github.com/sstephenson/rbenv" target="_blank">rbenv</a> but if you want to have full control over what are you installing because it will be your production system, then this post will show you how to do this.</p>
<p>To install Ruby from source you need to install some dependencies first<br />
<span id="more-95"></span></p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">apt-get update</span><br />
<br />
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #660033;">-y</span> <span style="color: #c20cb9; font-weight: bold;">install</span> build-essential zlib1g zlib1g-dev libxml2 libxml2-dev libxslt1-dev sqlite3 libsqlite3-dev <span style="color: #c20cb9; font-weight: bold;">locate</span> git-core libssl-dev openssl<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #660033;">-y</span> <span style="color: #c20cb9; font-weight: bold;">install</span> curl <span style="color: #c20cb9; font-weight: bold;">wget</span><br />
<br />
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #660033;">-y</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libreadline-dev<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #660033;">-y</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libz-dev<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #660033;">-y</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libssl-dev<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #660033;">-y</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">g++</span> libstdc++<span style="color: #000000;">6</span>-<span style="color: #000000;">4.4</span>-dev<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #660033;">-y</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libxml2-dev<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #660033;">-y</span> <span style="color: #c20cb9; font-weight: bold;">install</span> mysql-client<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #660033;">-y</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libmysql++-dev<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #660033;">-y</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libmysql++<span style="color: #000000;">3</span><br />
<br />
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #660033;">-y</span> <span style="color: #c20cb9; font-weight: bold;">install</span> tk tk-dev</div></div>
<p>Now you are ready to install the actual ruby binaries</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span><br />
<br />
<span style="color: #666666; font-style: italic;"># remove any previous source code</span><br />
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-r</span> ruby-1.9.2-<span style="color: #000000; font-weight: bold;">*</span><br />
<br />
<span style="color: #666666; font-style: italic;"># fetch the latest code</span><br />
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>ftp.ruby-lang.org<span style="color: #000000; font-weight: bold;">/</span>pub<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.9</span><span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p290.tar.gz<br />
<br />
<span style="color: #666666; font-style: italic;">#unpack it</span><br />
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xozf</span> ruby-1.9.2-p290.tar.gz<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> ruby-1.9.2-p290<br />
<br />
<span style="color: #666666; font-style: italic;">#edit Setup file</span><br />
<span style="color: #c20cb9; font-weight: bold;">vi</span> ext<span style="color: #000000; font-weight: bold;">/</span>Setup</div></div>
<p>In the <strong>ext/Setup</strong> file you need to uncomment the extensions that you need. I always leave commented out only <strong>Win32API</strong>, <strong>win32ole</strong> and <strong>tk</strong> because those extension are not necessary for web applications on Linux.</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#Win32API </span><br />
bigdecimal <br />
curses <br />
dbm <br />
digest <br />
digest<span style="color: #000000; font-weight: bold;">/</span>md5 <br />
digest<span style="color: #000000; font-weight: bold;">/</span>rmd160 <br />
digest<span style="color: #000000; font-weight: bold;">/</span>sha1 <br />
digest<span style="color: #000000; font-weight: bold;">/</span>sha2 <br />
dl <br />
etc <br />
fcntl <br />
gdbm <br />
iconv <br />
io<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">wait</span> <br />
nkf <br />
openssl <br />
pty <br />
racc<span style="color: #000000; font-weight: bold;">/</span>cparse <br />
readline <br />
ripper <br />
sdbm <br />
socket <br />
stringio <br />
strscan <br />
syck <br />
syslog <br />
<span style="color: #666666; font-style: italic;">#tk </span><br />
<span style="color: #666666; font-style: italic;">#win32ole </span><br />
zlib</div></div>
<p>After you have chosen your extensions you can compile the code</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--program-suffix</span>=1.9.2<br />
<br />
<span style="color: #666666; font-style: italic;"># OPENVZ note - adjust the vps configuration , especially the PRIVVMPAGES because compilation may fail silently sometimes</span><br />
<span style="color: #c20cb9; font-weight: bold;">make</span><br />
<br />
<span style="color: #666666; font-style: italic;"># OPENVZ note</span><br />
<span style="color: #666666; font-style: italic;"># tests sometimes fail in VPS-es because of lack of resources: sockets, memory etc.</span><br />
<span style="color: #666666; font-style: italic;"># adjust the configuration , especially the KMEMSIZE </span><br />
<span style="color: #666666; font-style: italic;"># and use &quot;cat /proc/user_beancounters&quot; to check the counters</span><br />
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #7a0874; font-weight: bold;">test</span><br />
<br />
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></div></div>
<p>After this installation all the ruby binaries will have suffix &#8220;1.9.2&#8243; but if you would like to keep the suffix and still be able to use shorter names, then just run those commands</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>erb1.9.2 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>erb<br />
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>gem1.9.2 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>gem<br />
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>irb1.9.2 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>irb<br />
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rake1.9.2 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rake<br />
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-sf</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rdoc1.9.2 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rdoc<br />
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-sf</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ri1.9.2 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ri<br />
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby1.9.2 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby<br />
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>testrb1.9.2 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>testrb</div></div>
<p>Ruby code includes <strong>gem</strong> binary which is usually outdated so to update this binary run this command</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">gem update <span style="color: #660033;">--system</span></div></div>
<p>Now everything is installed and ready for use if you have <strong>/usr/local/bin</strong> in your system PATH. If not then add this</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #007800;">$PATH</span> <br />
<span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #007800;">$PATH</span></div></div>
<p>to <strong>/root/.bash_profile</strong> (for root only) and <strong>/etc/profile</strong> (for all except root)</p>
<p>in <strong>/etc/profile</strong> do not add anything below</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">umask</span> 022</div></div>
<p>at the bottom of the file</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gemcoders.com/2011/09/12/ruby-1-9-2-installation-from-source/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Symfony2  pagination with controller as a service and data sorting</title>
		<link>http://blog.gemcoders.com/2011/09/11/symfony2-pagination-controller-service-data-sorting/</link>
		<comments>http://blog.gemcoders.com/2011/09/11/symfony2-pagination-controller-service-data-sorting/#comments</comments>
		<pubDate>Sun, 11 Sep 2011 23:21:16 +0000</pubDate>
		<dc:creator>Pawel Barcik</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[symfony2]]></category>

		<guid isPermaLink="false">http://blog.gemcoders.com/?p=51</guid>
		<description><![CDATA[Symfony2 doesn&#8217;t provide any good pagination tools out of the box so to solve this quite important problem I have created my own solution. I needed to be able to paginate data based on requested page and per_page parameters through GET and POST requests. Second important thing was to be able to sort displayed data [...]]]></description>
			<content:encoded><![CDATA[<p>Symfony2 doesn&#8217;t provide any good pagination tools out of the box so to solve this quite important problem I have created my own solution.</p>
<p>I needed to be able to paginate data based on requested page and per_page parameters through GET and POST requests. Second important thing was to be able to sort displayed data by id, title, etc. </p>
<p>I could have created some Paginator class but I wanted to be able to tweak each part of the process as I see fit on a per controller basis and I wanted to be able to access necessary functions through very short function calls directly in a controller.</p>
<p>I decided to extend all my controllers with necessary helper functions which would be available across all of them whenever I need to paginate something.</p>
<p>First problem was extending the controllers. Symfony2 docs page <a href="http://symfony.com/doc/2.0/book/controller.html" title="" target="_blank">http://symfony.com/doc/2.0/book/controller.html</a> shows you how to create controllers in a vary common way, but what it doesn&#8217;t say is that in this way you won&#8217;t be able to extend all controllers without running into various problems with access to the service container and Doctrine2 EntityManager which is needed to work with your data.</p>
<p>The solution to above problems is to use controllers as a service which allows you to use class inheritance, interfaces etc. in any way you want.</p>
<h2>Application setup</h2>
<p>Lets assume the application is configured as follows:</p>
<ul>
<li>bundle is located in <strong>src/Foo/DemoBundle</strong> </li>
<li>all controllers will extend <strong>ApplicationController</strong> class which extends <strong>Symfony\Bundle\FrameworkBundle\Controller\Controller</strong> </li>
<li>pagination template is located in here <strong>src/Foo/DemoBundle/Resources/views/Pagination/pagination.html.twig</strong> </li>
<li>all necessary twig macros will be stored in here <strong>src/Foo/DemoBundle/Resources/views/global_macros.html.twig</strong> </li>
</ul>
<p><span id="more-51"></span></p>
<h2>Controller as a Service</h2>
<p>To set up your controller as a service you need to modify your routing and service configuration. </p>
<p><strong>Foo/DemoBundle/Resources/config/services.yml</strong> file should be modified as follows:</p>
<div class="codecolorer-container yaml blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="yaml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007F45;">parameters</span>:<span style="color: green;"><br />
&nbsp; demo.products_controller.class</span><span style="font-weight: bold; color: brown;">: </span>Foo\DemoBundle\Controller\ProductsController<span style="color: #007F45;"><br />
services</span><span style="font-weight: bold; color: brown;">:<br />
</span><span style="color: blue;"># &nbsp;demo.example:</span><br />
<span style="color: blue;"># &nbsp; &nbsp;class: %demo.example.class%</span><br />
<span style="color: blue;"># &nbsp; &nbsp;arguments: [@service_id, &quot;plain_value&quot;, %parameter%]</span><span style="color: #007F45;"><br />
&nbsp; demo.products_controller</span>:<span style="color: green;"><br />
&nbsp; &nbsp; class</span><span style="font-weight: bold; color: brown;">: </span><span style="font-weight: bold; color: red;">%demo.products_controller.class%</span><span style="color: green;"><br />
&nbsp; &nbsp; arguments</span><span style="font-weight: bold; color: brown;">: </span><span class="br0">&#91;</span><span class="br0">&#93;</span><span style="color: #007F45;"><br />
&nbsp; &nbsp; calls</span><span style="font-weight: bold; color: brown;">:<br />
</span> &nbsp; &nbsp; &nbsp;- <span class="br0">&#91;</span> setContainer, <span class="br0">&#91;</span><span style="color: #CF00CF;">&quot;@service_container&quot;</span><span class="br0">&#93;</span> <span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp;- <span class="br0">&#91;</span> init, <span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="br0">&#93;</span></div></div>
<p>the &#8220;- [ init, [] ]&#8221; part will be used to trigger function call ProductsController.init() each time the controller is being instantiated. This function will take care of the configuration of all controllers but we will get back to this later on.</p>
<p>Now we need to update the routing config <strong>app/config/routing.yml</strong> file:</p>
<div class="codecolorer-container yaml blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="yaml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007F45;">products</span>:<span style="color: green;"><br />
&nbsp; pattern</span><span style="font-weight: bold; color: brown;">: </span> /products<span style="color: green;"><br />
&nbsp; defaults</span><span style="font-weight: bold; color: brown;">: </span><span class="br0">&#123;</span> _controller<span style="font-weight: bold; color: brown;">: </span>demo.products_controller:indexAction <span class="br0">&#125;</span><span style="color: green;"><br />
&nbsp; requirements</span><span style="font-weight: bold; color: brown;">: </span><span class="br0">&#123;</span> _method<span style="font-weight: bold; color: brown;">: </span>get <span class="br0">&#125;</span></div></div>
<p>If the controller would be set up as a &#8220;normal&#8221; controller , not a service , the configuration would look like this:</p>
<div class="codecolorer-container yaml blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="yaml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007F45;">products</span>:<span style="color: green;"><br />
&nbsp; pattern</span><span style="font-weight: bold; color: brown;">: </span> /products<span style="color: green;"><br />
&nbsp; defaults</span><span style="font-weight: bold; color: brown;">: </span><span class="br0">&#123;</span> _controller<span style="font-weight: bold; color: brown;">: </span>FooDemoBundle:Products:index <span class="br0">&#125;</span><span style="color: green;"><br />
&nbsp; requirements</span><span style="font-weight: bold; color: brown;">: </span><span class="br0">&#123;</span> _method<span style="font-weight: bold; color: brown;">: </span>get <span class="br0">&#125;</span></div></div>
<p>As you can see the controller reference notation is different.</p>
<p>To be able to add helper functions to all controllers we need to create <strong>ApplicationController</strong> which will be extended by all other controllers. This controller will also allow us to access merged <strong>GET</strong> and <strong>POST</strong> request parameters which will simplify a lot any request processing. <strong>ApplicationController</strong> will provide both pagination and data sorting helpers. As an extra feature to the data sorting and pagination we will make it persistent per each controller which allows you to go to any other page and then go back and have your chosen sorting and pagination options applied again.</p>
<div class="codecolorer-container php blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">namespace</span> Foo\DemoBundle\Controller<span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">use</span> Symfony\Bundle\FrameworkBundle\Controller\Controller<span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">use</span> Symfony\Component\HttpFoundation\ParameterBag<span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">class</span> ApplicationController <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$manager</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$perPageDefault</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">manager</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDoctrine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getEntityManager</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$request</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ParameterBag<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array_merge"><span style="color: #990000;">array_merge</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">all</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">all</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">perPageDefault</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;page&quot;</span><span style="color: #009900;">&#41;</span>? <a href="http://www.php.net/intval"><span style="color: #990000;">intval</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;page&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$page</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$page</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> perPage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$session</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;session&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$pagination</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pagination&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/is_array"><span style="color: #990000;">is_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pagination</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000088;">$pagination</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;per_page&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000088;">$perPage</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/intval"><span style="color: #990000;">intval</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;per_page&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pagination</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/get_class"><span style="color: #990000;">get_class</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;per_page&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000088;">$perPage</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pagination</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/get_class"><span style="color: #990000;">get_class</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;per_page&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000088;">$perPage</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">perPageDefault</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$perPage</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000088;">$perPage</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">perPageDefault</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000088;">$pagination</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/get_class"><span style="color: #990000;">get_class</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;per_page&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$perPage</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pagination&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pagination</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$perPage</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> orderBy<span style="color: #009900;">&#40;</span><span style="color: #000088;">$default</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$orderByData</span> <span style="color: #339933;">=</span> &nbsp;<a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;-&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;order_by&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$orderByData</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$orderByData</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$orderByData</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$default</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> orderDirection<span style="color: #009900;">&#40;</span><span style="color: #000088;">$default</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;asc&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$orderByData</span> <span style="color: #339933;">=</span> &nbsp;<a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;-&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;order_by&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$direction</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$default</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$orderByData</span> <span style="color: #339933;">&amp;&amp;</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$orderByData</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$orderByData</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$orderByData</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;up&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$direction</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;desc&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$direction</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;asc&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$direction</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now we need our <strong>ProductsController</strong> with <strong>indexAction</strong></p>
<div class="codecolorer-container php blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">namespace</span> Foo\DemoBundle\Controller<span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">use</span> Foo\DemoBundle\Entity\Product<span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">use</span> Symfony\Component\HttpFoundation\Request<span style="color: #339933;">;</span><br />
<br />
<br />
<span style="color: #000000; font-weight: bold;">class</span> ProductsController <span style="color: #000000; font-weight: bold;">extends</span> ApplicationController<br />
<span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">page</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">perPage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000088;">$queryBuilder</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">manager</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRepository</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FooDemoBundle:Product'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">createQueryBuilder</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'p'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">orderBy</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'p.'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">orderBy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">orderDirection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000088;">$rowCount</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$queryBuilder</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$queryBuilder</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">expr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><a href="http://www.php.net/count"><span style="color: #990000;">count</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'p.id'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #339933;">-&gt;</span><span style="color: #004000;">getQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSingleResult</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$queryBuilder</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'p'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFirstResult</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$offset</span> <span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMaxResults</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">perPage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">getQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$products</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResult</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FooDemoBundle:Products:index.html.twig'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;products&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$products</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;params&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;page&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">page</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;per_page&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">perPage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;page_count&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><a href="http://www.php.net/ceil"><span style="color: #990000;">ceil</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rowCount</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">perPage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;order_by&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">orderBy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;order_direction&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">orderDirection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> orderBy<span style="color: #009900;">&#40;</span><span style="color: #000088;">$default</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$orderBy</span> <span style="color: #339933;">=</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">orderBy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$default</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/in_array"><span style="color: #990000;">in_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$orderBy</span> <span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;title&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$orderBy</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$default</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Our <strong>ProductsController</strong> is overwriting <strong>orderBy</strong> function to set up default order and secure/limit the order_by parameter options. </p>
<h2>Pagination template, macros and sorting</h2>
<p>Now that the controllers are all set we need to create a <strong>Twig macro</strong> which will generate for us the necessary <strong>pagination widget</strong>. This macro is allowing you to specify your own pagination template so customizing the widget is very easy. </p>
<p>All the macros are located in <strong>Foo/DemoBundle/Resources/views/global_macros.html.twig</strong></p>
<div class="codecolorer-container smarty blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br /></div></td><td><div class="smarty codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> macro paginate<span style="color: #D36900;">&#40;</span>context, pagination_url, pagination_template, page_count, current_page, per_page, side_pages<span style="color: #D36900;">&#41;</span> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> spaceless <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> set side_pages <span style="color: #D36900;">=</span> side_pages|default<span style="color: #D36900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #D36900;">&#41;</span> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> set pagination_url <span style="color: #D36900;">=</span> pagination_url|default<span style="color: #D36900;">&#40;</span><span style="color: #ff0000;">&quot;#&quot;</span><span style="color: #D36900;">&#41;</span> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> <a href="http://smarty.php.net/if"><span style="color: #0600FF;">if</span></a> current_page <span style="color: #D36900;">&gt;</span> page_count <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> set current_page <span style="color: #D36900;">=</span> page_count <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> endif<span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> set left_start_page <span style="color: #D36900;">=</span> current_page - &nbsp;side_pages <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> <a href="http://smarty.php.net/if"><span style="color: #0600FF;">if</span></a> left_start_page <span style="color: #D36900;">&lt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> set left_start_page <span style="color: #D36900;">=</span> <span style="color: #cc66cc;">1</span> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> endif<span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> set left_pages <span style="color: #D36900;">=</span> current_page - left_start_page <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> set right_end_page <span style="color: #D36900;">=</span> current_page + &nbsp;side_pages <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> <a href="http://smarty.php.net/if"><span style="color: #0600FF;">if</span></a> right_end_page <span style="color: #D36900;">&gt;</span> page_count <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> set right_end_page <span style="color: #D36900;">=</span> page_count <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> endif<span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> set right_pages <span style="color: #D36900;">=</span> right_end_page - current_page <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> <a href="http://smarty.php.net/include"><span style="color: #0600FF;">include</span></a> pagination_template <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
<br />
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> endspaceless <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> endmacro<span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Next thing to do is to create pagination template</p>
<div class="codecolorer-container smarty blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br /></div></td><td><div class="smarty codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009000;">&lt;ul class='pagination'&gt;</span><br />
<br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> <a href="http://smarty.php.net/if"><span style="color: #0600FF;">if</span></a> left_pages <span style="color: #D36900;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009000;">&lt;li class='first'&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009000;">&lt;a href=&quot;{{pagination_url}}?{{ query_string({ &quot;page&quot;: 1 }, context.params.all()) }}&quot;&gt;</span>&amp;laquo; First<span style="color: #009000;">&lt;/a&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009000;">&lt;/li&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009000;">&lt;li class='prev'&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009000;">&lt;a href=&quot;{{pagination_url}}?{{ query_string({ &quot;page&quot;: (current_page - 1) }, context.params.all()) }}&quot;&gt;</span>&amp;lsaquo; Prev<span style="color: #009000;">&lt;/a&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009000;">&lt;/li&gt;</span><br />
&nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> <a href="http://smarty.php.net/if"><span style="color: #0600FF;">if</span></a> current_page - left_pages <span style="color: #D36900;">&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009000;">&lt;li class='page gap'&gt;</span>...<span style="color: #009000;">&lt;/li&gt;</span><br />
&nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> endif <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> for page_id in <span style="color: #D36900;">&#40;</span>current_page - left_pages<span style="color: #D36900;">&#41;</span>..<span style="color: #D36900;">&#40;</span>current_page - <span style="color: #cc66cc;">1</span><span style="color: #D36900;">&#41;</span> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009000;">&lt;li class='page'&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009000;">&lt;a href=&quot;{{pagination_url}}?{{ query_string({ &quot;page&quot;: page_id }, context.params.all()) }}&quot; rel=&quot;prev&quot;&gt;</span><span style="color: #D36900;">&#123;</span><span style="color: #D36900;">&#123;</span>page_id<span style="color: #D36900;">&#125;</span>}<span style="color: #009000;">&lt;/a&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009000;">&lt;/li&gt;</span><br />
&nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> endfor<span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> endif <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; <span style="color: #009000;">&lt;li class='page active'&gt;</span><br />
&nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">&#123;</span>current_page<span style="color: #D36900;">&#125;</span>}<br />
&nbsp; <span style="color: #009000;">&lt;/li&gt;</span><br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> <a href="http://smarty.php.net/if"><span style="color: #0600FF;">if</span></a> right_pages <span style="color: #D36900;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> for page_id in <span style="color: #D36900;">&#40;</span>current_page + <span style="color: #cc66cc;">1</span><span style="color: #D36900;">&#41;</span>..<span style="color: #D36900;">&#40;</span>current_page + right_pages<span style="color: #D36900;">&#41;</span> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009000;">&lt;li class='page'&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009000;">&lt;a href=&quot;{{pagination_url}}?{{ query_string({ &quot;page&quot;: page_id }, context.params.all()) }}&quot; rel=&quot;next&quot;&gt;</span><span style="color: #D36900;">&#123;</span><span style="color: #D36900;">&#123;</span>page_id<span style="color: #D36900;">&#125;</span>}<span style="color: #009000;">&lt;/a&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009000;">&lt;/li&gt;</span><br />
&nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> endfor<span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> <a href="http://smarty.php.net/if"><span style="color: #0600FF;">if</span></a> current_page + right_pages <span style="color: #D36900;">&lt;</span> page_count <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009000;">&lt;li class='page gap'&gt;</span>...<span style="color: #009000;">&lt;/li&gt;</span><br />
&nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> endif <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009000;">&lt;li class='next'&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009000;">&lt;a href=&quot;{{pagination_url}}?{{ query_string({ &quot;page&quot;: (current_page + 1) }, context.params.all()) }}&quot; &nbsp;rel=&quot;next&quot;&gt;</span>Next &amp;rsaquo;<span style="color: #009000;">&lt;/a&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009000;">&lt;/li&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009000;">&lt;li class='last'&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009000;">&lt;a href=&quot;{{pagination_url}}?{{ query_string({ &quot;page&quot;: (page_count) }, context.params.all()) }}&quot;&gt;</span>Last &amp;raquo;<span style="color: #009000;">&lt;/a&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009000;">&lt;/li&gt;</span><br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> endif <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
<span style="color: #009000;">&lt;/ul&gt;</span></div></td></tr></tbody></table></div>
<p>As you can see the above template is using my custom <strong>query_string</strong> Twig function which is merging new request parameters with the current ones and generates a query string, which is useful for paginating search results. To create your own custom Twig function you need to create <strong>Twig Extension</strong> but I won&#8217;t be showing this in this post.</p>
<p>To be able to sort data easily we will need two additional macros</p>
<div class="codecolorer-container smarty blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="smarty codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> macro order_by_string<span style="color: #D36900;">&#40;</span>order_by, current_order_by, current_order_direction, default_direction<span style="color: #D36900;">&#41;</span> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> spaceless <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> <a href="http://smarty.php.net/if"><span style="color: #0600FF;">if</span></a> current_order_by <span style="color: #D36900;">==</span> order_by <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> <a href="http://smarty.php.net/if"><span style="color: #0600FF;">if</span></a> current_order_direction <span style="color: #D36900;">==</span> <span style="color: #ff0000;">&quot;desc&quot;</span> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> set order_direction <span style="color: #D36900;">=</span> <span style="color: #ff0000;">&quot;down&quot;</span> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> <a href="http://smarty.php.net/else"><span style="color: #0600FF;">else</span></a> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> set order_direction <span style="color: #D36900;">=</span> <span style="color: #ff0000;">&quot;up&quot;</span> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> endif <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> <a href="http://smarty.php.net/else"><span style="color: #0600FF;">else</span></a> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> set order_direction <span style="color: #D36900;">=</span> default_direction|default<span style="color: #D36900;">&#40;</span><span style="color: #ff0000;">&quot;down&quot;</span><span style="color: #D36900;">&#41;</span> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> endif<span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">&#123;</span> order_by <span style="color: #D36900;">&#125;</span>}-<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">&#123;</span> order_direction <span style="color: #D36900;">&#125;</span>}<br />
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> endspaceless <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> endmacro<span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
<br />
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> macro order_by_class<span style="color: #D36900;">&#40;</span>order_by, order_by_param<span style="color: #D36900;">&#41;</span> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> spaceless <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> set css_class <span style="color: #D36900;">=</span> <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> <a href="http://smarty.php.net/if"><span style="color: #0600FF;">if</span></a> order_by_param <span style="color: #D36900;">==</span> order_by ~ <span style="color: #ff0000;">&quot;-up&quot;</span> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> set css_class <span style="color: #D36900;">=</span> <span style="color: #ff0000;">&quot;headerSortUp&quot;</span> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> endif<span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> <a href="http://smarty.php.net/if"><span style="color: #0600FF;">if</span></a> order_by_param <span style="color: #D36900;">==</span> order_by ~ <span style="color: #ff0000;">&quot;-down&quot;</span> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> set css_class <span style="color: #D36900;">=</span> <span style="color: #ff0000;">&quot;headerSortDown&quot;</span> <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> endif<span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">&#123;</span>css_class<span style="color: #D36900;">&#125;</span>}<br />
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> endspaceless <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> endmacro<span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Both those macros will help us to create appropriate order_by values for eg:</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">title-up<br />
title-down</div></td></tr></tbody></table></div>
<p>depending on the current state which allows us to easily toggle between how the data should be ordered.</p>
<p>With all this set up we can create the view template now</p>
<div class="codecolorer-container smarty blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br /></div></td><td><div class="smarty codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> <a href="http://smarty.php.net/include"><span style="color: #0600FF;">include</span></a> <span style="color: #ff0000;">'FooDemoBundle::global_macros.html.twig'</span> as global_macros <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
<br />
<span style="color: #009000;">&lt;ul class=&quot;&quot;&gt;</span><br />
&nbsp; <span style="color: #009000;">&lt;li&gt;</span><br />
&nbsp; &nbsp; Per page:<br />
&nbsp; <span style="color: #009000;">&lt;/li&gt;</span><br />
&nbsp; <span style="color: #009000;">&lt;li&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009000;">&lt;a href=&quot;?{{ query_string({ &quot;page&quot;: 1, &quot;per_page&quot;: 10 &nbsp;}, params.all()) }}&quot;&gt;</span>10<span style="color: #009000;">&lt;/a&gt;</span><br />
&nbsp; <span style="color: #009000;">&lt;/li&gt;</span><br />
&nbsp; <span style="color: #009000;">&lt;li&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009000;">&lt;a href=&quot;?{{ query_string({ &quot;page&quot;: 1, &quot;per_page&quot;: 20 &nbsp;}, params.all()) }}&quot;&gt;</span>20<span style="color: #009000;">&lt;/a&gt;</span><br />
<br />
&nbsp; <span style="color: #009000;">&lt;/li&gt;</span><br />
&nbsp; <span style="color: #009000;">&lt;li&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009000;">&lt;a href=&quot;?{{ query_string({ &quot;page&quot;: 1, &quot;per_page&quot;: 50 &nbsp;}, params.all()) }}&quot;&gt;</span>50<span style="color: #009000;">&lt;/a&gt;</span><br />
&nbsp; <span style="color: #009000;">&lt;/li&gt;</span><br />
&nbsp; <span style="color: #009000;">&lt;li&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009000;">&lt;a href=&quot;?{{ query_string({ &quot;page&quot;: 1, &quot;per_page&quot;: 100 &nbsp;}, params.all()) }}&quot;&gt;</span>100<span style="color: #009000;">&lt;/a&gt;</span><br />
&nbsp; <span style="color: #009000;">&lt;/li&gt;</span><br />
<span style="color: #009000;">&lt;/ul&gt;</span><br />
<br />
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">&#123;</span> global_macros.<span style="color: #006600;">paginate</span><span style="color: #D36900;">&#40;</span>_context, path<span style="color: #D36900;">&#40;</span><span style="color: #ff0000;">&quot;products&quot;</span><span style="color: #D36900;">&#41;</span>, pagination_template, page_count, page, per_page, <span style="color: #cc66cc;">3</span><span style="color: #D36900;">&#41;</span> <span style="color: #D36900;">&#125;</span>}<br />
<span style="color: #009000;">&lt;table id=&quot;products-table&quot;&gt;</span><br />
&nbsp; <span style="color: #009000;">&lt;thead&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009000;">&lt;tr&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009000;">&lt;th class=&quot;{{ global_macros.order_by_class(&quot;id&quot;, params.get(&quot;order_by&quot;)) }}&quot;&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009000;">&lt;a href=&quot;{{ url(&quot;products&quot;) }}?order_by={{ global_macros.order_by_string(&quot;id&quot;, order_by, order_direction) }}&quot;&gt;</span>product ID<span style="color: #009000;">&lt;/a&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009000;">&lt;/th&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009000;">&lt;th class=&quot;{{ global_macros.order_by_class(&quot;title&quot;, params.get(&quot;order_by&quot;)) }}&quot;&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009000;">&lt;a href=&quot;{{ url(&quot;products&quot;) }}?order_by={{ global_macros.order_by_string(&quot;title&quot;, order_by, order_direction) }}&quot;&gt;</span>title<span style="color: #009000;">&lt;/a&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009000;">&lt;/th&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009000;">&lt;/tr&gt;</span><br />
&nbsp; <span style="color: #009000;">&lt;/thead&gt;</span><br />
&nbsp; <span style="color: #009000;">&lt;tbody&gt;</span><br />
&nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> for element in products <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009000;">&lt;tr&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009000;">&lt;td class=&quot;id-column&quot; &gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">&#123;</span>element.<span style="color: #006600;">id</span><span style="color: #D36900;">&#125;</span>}<br />
&nbsp; &nbsp; &nbsp; <span style="color: #009000;">&lt;/td&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009000;">&lt;td class=&quot;title-column&quot;&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">&#123;</span>element.<span style="color: #006600;">title</span><span style="color: #D36900;">&#125;</span>}<br />
&nbsp; &nbsp; &nbsp; <span style="color: #009000;">&lt;/td&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009000;">&lt;/tr&gt;</span><br />
&nbsp; &nbsp; <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">%</span> endfor <span style="color: #D36900;">%</span><span style="color: #D36900;">&#125;</span><br />
&nbsp; <span style="color: #009000;">&lt;/tbody&gt;</span><br />
<span style="color: #009000;">&lt;/table&gt;</span><br />
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">&#123;</span> global_macros.<span style="color: #006600;">paginate</span><span style="color: #D36900;">&#40;</span>_context, path<span style="color: #D36900;">&#40;</span><span style="color: #ff0000;">&quot;products&quot;</span><span style="color: #D36900;">&#41;</span>, pagination_template, page_count, page, per_page, <span style="color: #cc66cc;">3</span><span style="color: #D36900;">&#41;</span> <span style="color: #D36900;">&#125;</span>}</div></td></tr></tbody></table></div>
<h2>Final thoughts</h2>
<p>As you can see, this pagination code is very flexible and can be customized to fit any purpose , especially if you need to create paginated search results which can be bookmarked.</p>
<p>Certain parts of this code have been ported from <strong>Ruby on Rails</strong> application that I have created before which shows that this solution should be portable to any other MVC and templating framework.</p>
<p><strong>EDIT:</strong><br />
Updated the pagination macro and template to use &#8220;pagination_url&#8221; passed as parameter as intended , because the template should be reusable.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gemcoders.com/2011/09/11/symfony2-pagination-controller-service-data-sorting/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP Suhosin config</title>
		<link>http://blog.gemcoders.com/2011/08/17/php-suhosin-config/</link>
		<comments>http://blog.gemcoders.com/2011/08/17/php-suhosin-config/#comments</comments>
		<pubDate>Wed, 17 Aug 2011 00:45:26 +0000</pubDate>
		<dc:creator>Pawel Barcik</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.gemcoders.com/?p=40</guid>
		<description><![CDATA[As an addition to my previous post : FastCGI php 5.3.6 compilation on Ubuntu 8.04 you have here a config settings for Suhosin which you can use as a base for further modifications: &#91;suhosin&#93; ;suhosin.filter.action = suhosin.cookie.max_array_depth = 100 suhosin.cookie.max_array_index_length = 32500 ;suhosin.cookie.max_name_length = 64 ;suhosin.cookie.max_totalname_length = 256 ;suhosin.cookie.max_value_length = 10000 suhosin.cookie.max_vars = 5000 ;suhosin.cookie.disallow_nul [...]]]></description>
			<content:encoded><![CDATA[<p>As an addition to my previous post :</p>
<p><a href="http://blog.gemcoders.com/2011/08/17/fastcgi-php-5-3-6-compilation-ubuntu-8-04/">FastCGI php 5.3.6 compilation on Ubuntu 8.04</a></p>
<p>you have here a config settings for Suhosin which you can use as a base for further modifications:</p>
<p><span id="more-40"></span></p>
<div class="codecolorer-container php blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&#91;</span>suhosin<span style="color: #009900;">&#93;</span><br />
<br />
<br />
<br />
<span style="color: #339933;">;</span>suhosin<span style="color: #339933;">.</span>filter<span style="color: #339933;">.</span>action <span style="color: #339933;">=</span><br />
<br />
suhosin<span style="color: #339933;">.</span>cookie<span style="color: #339933;">.</span>max_array_depth <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><br />
<br />
suhosin<span style="color: #339933;">.</span>cookie<span style="color: #339933;">.</span>max_array_index_length <span style="color: #339933;">=</span> <span style="color: #cc66cc;">32500</span><br />
<br />
<span style="color: #339933;">;</span>suhosin<span style="color: #339933;">.</span>cookie<span style="color: #339933;">.</span>max_name_length <span style="color: #339933;">=</span> <span style="color: #cc66cc;">64</span><br />
<br />
<span style="color: #339933;">;</span>suhosin<span style="color: #339933;">.</span>cookie<span style="color: #339933;">.</span>max_totalname_length <span style="color: #339933;">=</span> <span style="color: #cc66cc;">256</span><br />
<br />
<span style="color: #339933;">;</span>suhosin<span style="color: #339933;">.</span>cookie<span style="color: #339933;">.</span>max_value_length <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10000</span><br />
<br />
suhosin<span style="color: #339933;">.</span>cookie<span style="color: #339933;">.</span>max_vars <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5000</span><br />
<br />
<span style="color: #339933;">;</span>suhosin<span style="color: #339933;">.</span>cookie<span style="color: #339933;">.</span>disallow_nul <span style="color: #339933;">=</span> on<br />
<br />
suhosin<span style="color: #339933;">.</span>get<span style="color: #339933;">.</span>max_array_depth <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><br />
<br />
suhosin<span style="color: #339933;">.</span>get<span style="color: #339933;">.</span>max_array_index_length <span style="color: #339933;">=</span> <span style="color: #cc66cc;">32500</span><br />
<br />
<span style="color: #339933;">;</span>suhosin<span style="color: #339933;">.</span>get<span style="color: #339933;">.</span>max_name_length <span style="color: #339933;">=</span> <span style="color: #cc66cc;">64</span><br />
<br />
<span style="color: #339933;">;</span>suhosin<span style="color: #339933;">.</span>get<span style="color: #339933;">.</span>max_totalname_length <span style="color: #339933;">=</span> <span style="color: #cc66cc;">256</span><br />
<br />
suhosin<span style="color: #339933;">.</span>get<span style="color: #339933;">.</span>max_value_length <span style="color: #339933;">=</span> <span style="color: #cc66cc;">512000</span><br />
<br />
suhosin<span style="color: #339933;">.</span>get<span style="color: #339933;">.</span>max_vars <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5000</span><br />
<br />
<span style="color: #339933;">;</span>suhosin<span style="color: #339933;">.</span>get<span style="color: #339933;">.</span>disallow_nul <span style="color: #339933;">=</span> on<br />
<br />
suhosin<span style="color: #339933;">.</span>post<span style="color: #339933;">.</span>max_array_depth <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><br />
<br />
suhosin<span style="color: #339933;">.</span>post<span style="color: #339933;">.</span>max_array_index_length <span style="color: #339933;">=</span> <span style="color: #cc66cc;">32500</span><br />
<br />
<span style="color: #339933;">;</span>suhosin<span style="color: #339933;">.</span>post<span style="color: #339933;">.</span>max_name_length <span style="color: #339933;">=</span> <span style="color: #cc66cc;">64</span><br />
<br />
<span style="color: #339933;">;</span>suhosin<span style="color: #339933;">.</span>post<span style="color: #339933;">.</span>max_totalname_length <span style="color: #339933;">=</span> <span style="color: #cc66cc;">256</span><br />
<br />
suhosin<span style="color: #339933;">.</span>post<span style="color: #339933;">.</span>max_value_length <span style="color: #339933;">=</span> <span style="color: #cc66cc;">512000</span><br />
<br />
suhosin<span style="color: #339933;">.</span>post<span style="color: #339933;">.</span>max_vars <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5000</span><br />
<br />
<span style="color: #339933;">;</span>suhosin<span style="color: #339933;">.</span>post<span style="color: #339933;">.</span>disallow_nul <span style="color: #339933;">=</span> on<br />
<br />
suhosin<span style="color: #339933;">.</span>request<span style="color: #339933;">.</span>max_array_depth <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><br />
<br />
suhosin<span style="color: #339933;">.</span>request<span style="color: #339933;">.</span>max_array_index_length <span style="color: #339933;">=</span> <span style="color: #cc66cc;">32500</span><br />
<br />
<span style="color: #339933;">;</span>suhosin<span style="color: #339933;">.</span>request<span style="color: #339933;">.</span>max_totalname_length <span style="color: #339933;">=</span> <span style="color: #cc66cc;">256</span><br />
<br />
suhosin<span style="color: #339933;">.</span>request<span style="color: #339933;">.</span>max_value_length <span style="color: #339933;">=</span> <span style="color: #cc66cc;">512000</span><br />
<br />
suhosin<span style="color: #339933;">.</span>request<span style="color: #339933;">.</span>max_vars <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5000</span><br />
<br />
<span style="color: #339933;">;</span>suhosin<span style="color: #339933;">.</span>request<span style="color: #339933;">.</span>max_varname_length <span style="color: #339933;">=</span> <span style="color: #cc66cc;">64</span><br />
<br />
<span style="color: #339933;">;</span>suhosin<span style="color: #339933;">.</span>request<span style="color: #339933;">.</span>disallow_nul <span style="color: #339933;">=</span> on<br />
<br />
suhosin<span style="color: #339933;">.</span>upload<span style="color: #339933;">.</span>max_uploads <span style="color: #339933;">=</span> <span style="color: #cc66cc;">25</span><br />
<br />
<span style="color: #339933;">;</span>suhosin<span style="color: #339933;">.</span>upload<span style="color: #339933;">.</span>disallow_elf <span style="color: #339933;">=</span> on<br />
<br />
<span style="color: #339933;">;</span>suhosin<span style="color: #339933;">.</span>upload<span style="color: #339933;">.</span>disallow_binary <span style="color: #339933;">=</span> off<br />
<br />
<span style="color: #339933;">;</span>suhosin<span style="color: #339933;">.</span>upload<span style="color: #339933;">.</span>remove_binary <span style="color: #339933;">=</span> off<br />
<br />
<span style="color: #339933;">;</span>suhosin<span style="color: #339933;">.</span>upload<span style="color: #339933;">.</span>verification_script <span style="color: #339933;">=</span><br />
<br />
<span style="color: #339933;">;</span>suhosin<span style="color: #339933;">.</span>session<span style="color: #339933;">.</span>max_id_length <span style="color: #339933;">=</span> <span style="color: #cc66cc;">128</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.gemcoders.com/2011/08/17/php-suhosin-config/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FastCGI php 5.3.6 compilation on Ubuntu 8.04</title>
		<link>http://blog.gemcoders.com/2011/08/17/fastcgi-php-5-3-6-compilation-ubuntu-8-04/</link>
		<comments>http://blog.gemcoders.com/2011/08/17/fastcgi-php-5-3-6-compilation-ubuntu-8-04/#comments</comments>
		<pubDate>Wed, 17 Aug 2011 00:36:43 +0000</pubDate>
		<dc:creator>Pawel Barcik</dc:creator>
				<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[ubuntu 8.04]]></category>

		<guid isPermaLink="false">http://blog.gemcoders.com/?p=11</guid>
		<description><![CDATA[In this article I will show you how to compile php 5.3 on Ubuntu 8.04 but it should work in a similar manner on later distributions. Installation EDIT: 1 added some new dependencies: libicu-dev g++ libmysqlclient-dev First some dependencies: apt-get install make gcc autoconf bison re2c libxpm-dev libsasl2-dev libpspell-dev libreadline5-dev libsnmp-dev #apt-get install apache2 apache2-mpm-prefork [...]]]></description>
			<content:encoded><![CDATA[<p>In this article I will show you how to compile php 5.3 on Ubuntu 8.04 but it should work in a similar manner on later distributions.</p>
<h2>Installation</h2>
<p><strong>EDIT: 1</strong></p>
<ul>
<li>added some new dependencies: libicu-dev g++ libmysqlclient-dev</li>
</ul>
<p>First some dependencies:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">apt-get install</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #c20cb9; font-weight: bold;">autoconf</span> <span style="color: #c20cb9; font-weight: bold;">bison</span> re2c libxpm-dev libsasl2-dev libpspell-dev libreadline5-dev libsnmp-dev<br />
<br />
<span style="color: #666666; font-style: italic;">#apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev apache2-utils apache2.2-common</span><br />
<span style="color: #c20cb9; font-weight: bold;">apt-get install</span> aspell libaspell-dev libxml2 libsnmp-base libsnmp15 libxml2-dev<br />
<span style="color: #c20cb9; font-weight: bold;">apt-get install</span> libbz2-dev libzip-dev libzip1 zlib1g zlib1g-dev<br />
<span style="color: #c20cb9; font-weight: bold;">apt-get install</span> curl libcurl4-openssl-dev libcurl3 libcurl3-gnutls<br />
<span style="color: #c20cb9; font-weight: bold;">apt-get install</span> libc-client-dev libfreetype6 libfreetype6-dev<br />
<span style="color: #c20cb9; font-weight: bold;">apt-get install</span> libjpeg62 libjpeg62-dev libpng12-<span style="color: #000000;">0</span> libpng12-dev<br />
<span style="color: #c20cb9; font-weight: bold;">apt-get install</span> libmcrypt-dev libmcrypt4 libtidy-dev libxslt1-dev libicu-dev <span style="color: #c20cb9; font-weight: bold;">g++</span> libmysqlclient-dev<br />
<br />
<span style="color: #666666; font-style: italic;"># for /usr/bin/apxs2</span><br />
<span style="color: #666666; font-style: italic;">#aptitude install apache2-threaded-dev apache2-utils apache2.2-common</span><br />
<br />
<span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libicu-dev libicu38<br />
<br />
<span style="color: #666666; font-style: italic;">#aptitude install mysql-server-core-5.0 </span><br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">#aptitude install mysql-common mysql-server mysql-server-5.0 mysql-client mysql-client-5.0 mysql-server-core-5.0</span></div></div>
<p>I have commented out the the dependencies which are needed for compiling the apache2 module because in this post I want to show you how to get the the php5-cgi binary<br />
which is a bit tricky because you can&#8217;t compile all binaries at once and you need to know which options to disable to get the CGI .</p>
<p>No we are going to need the php&#8217;s source code:<br />
<span id="more-11"></span></p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;"># go to your source directory</span><br />
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>src<br />
<br />
<span style="color: #666666; font-style: italic;">#remove previous source folder if needed</span><br />
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> php-5.3.6<br />
<br />
<span style="color: #666666; font-style: italic;">#fetch the latest source </span><br />
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>uk.php.net<span style="color: #000000; font-weight: bold;">/</span>distributions<span style="color: #000000; font-weight: bold;">/</span>php-5.3.6.tar.gz<br />
<br />
<span style="color: #666666; font-style: italic;"># -o means that we wont preserve the owner, there is also &nbsp;--no-same-permissions</span><br />
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-oxzf</span> php-5.3.6.tar.gz<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> php-5.3.6<br />
<br />
<span style="color: #666666; font-style: italic;"># with this command you can apply appropriate ownership rights</span><br />
<span style="color: #666666; font-style: italic;"># if you skip the -o paramater above</span><br />
<span style="color: #666666; font-style: italic;"># chown -R root:root</span></div></div>
<p>Now lets prepare the source for compilation:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#if recompiling</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;make clean</span><br />
<br />
<span style="color: #666666; font-style: italic;"># you can display configuration options</span><br />
<span style="color: #666666; font-style: italic;"># ./configure --help</span><br />
<br />
<span style="color: #666666; font-style: italic;">#removed options</span><br />
<span style="color: #666666; font-style: italic;"># --disable-short-tags \</span><br />
<span style="color: #666666; font-style: italic;"># --with-apxs2=/usr/bin/apxs2 \</span><br />
<span style="color: #666666; font-style: italic;"># --enable-fpm \</span><br />
<span style="color: #666666; font-style: italic;"># --with-fpm-user=phpfpm \</span><br />
<span style="color: #666666; font-style: italic;"># --with-fpm-group=phpfpm \</span><br />
<br />
<br />
<span style="color: #007800;">PARENT_FOLDER_LOCATION</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>php5.3<br />
<br />
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #007800;">$PARENT_FOLDER_LOCATION</span> \<br />
<span style="color: #660033;">--with-config-file-path</span>=<span style="color: #007800;">$PARENT_FOLDER_LOCATION</span> \<br />
<span style="color: #660033;">--with-config-file-scan-dir</span>=<span style="color: #007800;">$PARENT_FOLDER_LOCATION</span><span style="color: #000000; font-weight: bold;">/</span>conf.d \<br />
<span style="color: #660033;">--program-suffix</span>=<span style="color: #000000;">5.3</span> \<br />
<span style="color: #660033;">--disable-cli</span> \<br />
<span style="color: #660033;">--enable-cgi</span> \<br />
<span style="color: #660033;">--enable-inline-optimization</span> \<br />
<span style="color: #660033;">--enable-mbregex</span> \<br />
<span style="color: #660033;">--with-pcre-regex</span> \<br />
<span style="color: #660033;">--with-pear</span> \<br />
<span style="color: #660033;">--enable-intl</span> \<br />
<span style="color: #660033;">--without-t1lib</span> \<br />
<span style="color: #660033;">--enable-pcntl</span> \<br />
<span style="color: #660033;">--with-tsrm-pthreads</span> \<br />
<span style="color: #660033;">--with-mysqli</span>=mysqlnd \<br />
<span style="color: #660033;">--with-mysql</span>=mysqlnd \<br />
<span style="color: #660033;">--with-pdo-mysql</span> \<br />
<span style="color: #660033;">--with-openssl</span> \<br />
<span style="color: #660033;">--with-zlib</span> \<br />
<span style="color: #660033;">--enable-sysvmsg</span> \<br />
<span style="color: #660033;">--enable-sysvsem</span> \<br />
<span style="color: #660033;">--enable-sysvshm</span> \<br />
<span style="color: #660033;">--enable-bcmath</span> \<br />
<span style="color: #660033;">--with-bz2</span> \<br />
<span style="color: #660033;">--enable-calendar</span> \<br />
<span style="color: #660033;">--enable-exif</span> \<br />
<span style="color: #660033;">--enable-ftp</span> \<br />
<span style="color: #660033;">--with-gd</span> \<br />
<span style="color: #660033;">--with-jpeg-dir</span>=<span style="color: #007800;">$PARENT_FOLDER_LOCATION</span><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib \<br />
<span style="color: #660033;">--with-png-dir</span>=<span style="color: #007800;">$PARENT_FOLDER_LOCATION</span><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib \<br />
<span style="color: #660033;">--with-xpm-dir</span>=<span style="color: #007800;">$PARENT_FOLDER_LOCATION</span><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib \<br />
<span style="color: #660033;">--enable-gd-native-ttf</span> \<br />
<span style="color: #660033;">--enable-gd-jis-conv</span> \<br />
<span style="color: #660033;">--with-iconv-dir</span> \<br />
<span style="color: #660033;">--with-gettext</span> \<br />
<span style="color: #660033;">--with-imap</span> \<br />
<span style="color: #660033;">--with-imap-ssl</span> \<br />
<span style="color: #660033;">--with-ldap</span> \<br />
<span style="color: #660033;">--with-ldap-sasl</span> \<br />
<span style="color: #660033;">--enable-mbstring</span> \<br />
<span style="color: #660033;">--with-mcrypt</span> \<br />
<span style="color: #660033;">--with-mhash</span> \<br />
<span style="color: #660033;">--with-pspell</span> \<br />
<span style="color: #660033;">--with-readline</span> \<br />
<span style="color: #660033;">--with-snmp</span> \<br />
<span style="color: #660033;">--enable-soap</span> \<br />
<span style="color: #660033;">--enable-sockets</span> \<br />
<span style="color: #660033;">--with-sqlite</span> \<br />
<span style="color: #660033;">--enable-sqlite-utf8</span> \<br />
<span style="color: #660033;">--enable-wddx</span> \<br />
<span style="color: #660033;">--with-xmlrpc</span> \<br />
<span style="color: #660033;">--with-xsl</span> \<br />
<span style="color: #660033;">--enable-zip</span> \<br />
<span style="color: #660033;">--with-kerberos</span> \<br />
<span style="color: #660033;">--with-tidy</span> \<br />
<span style="color: #660033;">--with-curl</span> \<br />
<span style="color: #660033;">--with-curlwrappers</span></div></div>
<p>Lets compile the code now:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;"># this will compile the code using multiple processor cores to speed things up</span><br />
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #660033;">-j4</span><br />
<br />
<span style="color: #666666; font-style: italic;"># installing the binaries</span><br />
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span><br />
<span style="color: #666666; font-style: italic;">#or </span><br />
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-k</span><br />
<span style="color: #666666; font-style: italic;"># -k will allow you to process the installation even if there are Apache related errors</span></div></div>
<p>By default this installation should look for config files here:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007800;">$PARENT_FOLDER_LOCATION</span><span style="color: #000000; font-weight: bold;">/</span>conf.d<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #666666; font-style: italic;"># and</span><br />
<span style="color: #007800;">$PARENT_FOLDER_LOCATION</span><span style="color: #000000; font-weight: bold;">/</span>php.ini</div></div>
<p>To make your life easier it is best to copy your configs from a distribution which allows installation of php 5.3 , for e.g Ubuntu 10.04:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #007800;">$PARENT_FOLDER_LOCATION</span><span style="color: #000000; font-weight: bold;">/</span>conf.d<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #666666; font-style: italic;">#copy here ubuntu php 5.3 configs from you local machine which are located in /etc/php5/cgi/conf.d/ folder if you plan on using FastCGI</span><br />
<span style="color: #666666; font-style: italic;">#copy here ubuntu php 5.3 php.ini from here /etc/php5/cgi/</span></div></div>
<p>If you are using FastCGI , <strong>DISABLE PATH RESOLUTION / FIXING (!!!) </strong>because it will allow to execute code from images or other uploaded files with urls like this <strong>&#8220;http://example.com/images/foo/hacker.jpg/test/fake.php&#8221;</strong>.</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!!!!!!!!!!DISABLE PATH RESOLUTION / FIXING !!!!!!!!!!!!!</span><br />
<span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #007800;">$PARENT_FOLDER_LOCATION</span><span style="color: #000000; font-weight: bold;">/</span>php.ini<br />
<span style="color: #666666; font-style: italic;">#####</span><br />
...<br />
cgi.fix_pathinfo=<span style="color: #000000;">0</span><br />
...<br />
<span style="color: #666666; font-style: italic;">#####</span></div></div>
<p>If you would try to install some additional extensions through PEAR it will complain about not being able to find php binary so to solve this you can do this:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #007800;">$PARENT_FOLDER_LOCATION</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>php-cgi5.3 <span style="color: #007800;">$PARENT_FOLDER_LOCATION</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>php</div></div>
<p>but it might collide with your other php binary files, depending on your system $PATH settings</p>
<p>After the installation all your files should be in $PARENT_FOLDER_LOCATION which in my case was /usr/local/php5.3/:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">root root &nbsp; &nbsp;<span style="color: #000000;">77</span> Aug &nbsp;<span style="color: #000000;">4</span> 03:<span style="color: #000000;">25</span> .<br />
root root &nbsp;<span style="color: #000000;">4096</span> Aug &nbsp;<span style="color: #000000;">5</span> <span style="color: #000000;">19</span>:<span style="color: #000000;">50</span> ..<br />
root root &nbsp; &nbsp;<span style="color: #000000;">69</span> Aug &nbsp;<span style="color: #000000;">4</span> 02:<span style="color: #000000;">26</span> bin<br />
root root &nbsp; &nbsp;<span style="color: #000000;">77</span> Aug &nbsp;<span style="color: #000000;">4</span> 03:<span style="color: #000000;">35</span> conf.d<br />
root root &nbsp; &nbsp;<span style="color: #000000;">16</span> Aug &nbsp;<span style="color: #000000;">4</span> 02:08 include<br />
root root &nbsp; &nbsp;<span style="color: #000000;">16</span> Aug &nbsp;<span style="color: #000000;">4</span> 02:08 lib<br />
root root &nbsp; &nbsp;<span style="color: #000000;">17</span> Aug &nbsp;<span style="color: #000000;">4</span> 02:09 <span style="color: #c20cb9; font-weight: bold;">man</span><br />
root root <span style="color: #000000;">67594</span> Aug &nbsp;<span style="color: #000000;">4</span> 03:<span style="color: #000000;">28</span> php.ini</div></div>
<p>The $PARENT_FOLDER_LOCATION/bin should look like this:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">root root &nbsp; &nbsp; &nbsp; <span style="color: #000000;">69</span> Aug &nbsp;<span style="color: #000000;">4</span> 02:<span style="color: #000000;">26</span> .<br />
root root &nbsp; &nbsp; &nbsp; <span style="color: #000000;">77</span> Aug &nbsp;<span style="color: #000000;">4</span> 03:<span style="color: #000000;">25</span> ..<br />
root root &nbsp; &nbsp; &nbsp; <span style="color: #000000;">32</span> Aug &nbsp;<span style="color: #000000;">4</span> 02:<span style="color: #000000;">26</span> php -<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>php5.3<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>php-cgi5.3<br />
root root <span style="color: #000000;">31487388</span> Aug &nbsp;<span style="color: #000000;">4</span> 02:08 php-cgi5.3<br />
root root &nbsp; &nbsp; <span style="color: #000000;">3612</span> Aug &nbsp;<span style="color: #000000;">4</span> 02:09 php-config5.3<br />
root root &nbsp; &nbsp; <span style="color: #000000;">4516</span> Aug &nbsp;<span style="color: #000000;">4</span> 02:09 phpize5.3</div></div>
<p>as you can see the php-cgi5.3 is quite big (~32MB) because all the extensions are compiled into the binary, but a regular php-cgi file from an Ubuntu installation is around 9MB so it is not much of a problem because you get the benefit of simplicity of the installation.</p>
<h2>Suchosin extension</h2>
<p>To make this installation more secure you will need the Suhosin Extension (not patch, there is no patch for php 5.3.6 as of yet).</p>
<p>This is how you can install it:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>src <br />
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>download.suhosin.org<span style="color: #000000; font-weight: bold;">/</span>suhosin-0.9.32.1.tar.gz<br />
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-ozxf</span> suhosin-0.9.32.1.tar.gz<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> suhosin-0.9.32.1<br />
<br />
<span style="color: #666666; font-style: italic;">#run this in suhosin's folder</span><br />
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>php5.3<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>phpize5.3<br />
<br />
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #007800;">$PARENT_FOLDER_LOCATION</span> <span style="color: #660033;">--with-php-config</span>=<span style="color: #007800;">$PARENT_FOLDER_LOCATION</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>php-config5.3 &nbsp;<span style="color: #660033;">--enable-suhosin</span> <span style="color: #660033;">--includedir</span>=<span style="color: #007800;">$PARENT_FOLDER_LOCATION</span><span style="color: #000000; font-weight: bold;">/</span>include <br />
<br />
<span style="color: #c20cb9; font-weight: bold;">make</span><br />
<br />
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></div></div>
<p>after this installation you should be able to check if it is properly installed with this command or through the phpinfo() page:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>php5.3<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>php-cgi5.3 <span style="color: #660033;">-v</span><br />
<br />
PHP 5.3.6 <span style="color: #7a0874; font-weight: bold;">&#40;</span>cgi-fcgi<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>built: Aug &nbsp;<span style="color: #000000;">4</span> <span style="color: #000000;">2011</span> 02:07:<span style="color: #000000;">49</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
Copyright <span style="color: #7a0874; font-weight: bold;">&#40;</span>c<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">1997</span>-<span style="color: #000000;">2011</span> The PHP Group<br />
Zend Engine v2.3.0, Copyright <span style="color: #7a0874; font-weight: bold;">&#40;</span>c<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">1998</span>-<span style="color: #000000;">2011</span> Zend Technologies<br />
&nbsp; &nbsp; with Suhosin v0.9.32.1, Copyright <span style="color: #7a0874; font-weight: bold;">&#40;</span>c<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">2007</span>-<span style="color: #000000;">2010</span>, by SektionEins GmbH</div></div>
<p>The &#8221; with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH&#8221; line will tell you if Suhosin is installed properly.</p>
<h2>Possible issues with the installation</h2>
<p>Apache related error:</p>
<blockquote><p>
apxs:Error: Activation failed for custom /etc/apache2/httpd.conf file.. apxs:Error: At least one `LoadModule&#8217; directive already has to exist.. make[2]: *** [mod_xmlent-install] Error 1 make[1]: *** [mod_xmlent-install] Error 2
</p></blockquote>
<p>Fix:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;"># add this to the etc/apache2/httpd.conf</span><br />
<span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #007800;">$PARENT_FOLDER_LOCATION</span><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>httpd.conf<br />
<span style="color: #666666; font-style: italic;">######</span><br />
<span style="color: #666666; font-style: italic;"># dummy comment</span><br />
LoadModule dummy_module <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>modules<span style="color: #000000; font-weight: bold;">/</span>mod_dummy.so <br />
LoadModule mod_xmlent <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>modules<span style="color: #000000; font-weight: bold;">/</span>mod_xmlent.so<br />
<span style="color: #666666; font-style: italic;">######</span></div></div>
<p>I have tried this quick fix with a single LoadModule line but it doesn&#8217;t seem to work.</p>
<p>If after the installation PHP would complain about not being able to load some extensions, use this fix:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;"># </span>Add: <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>php5.3<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>php to your php.ini include_path</div></div>
<h2>Related tasks</h2>
<p>After you installed new php binaries don&#8217;t forget to double check your new config files to prepare them for the production environment , especially fine tune your Suhosin settings because the default values are pretty &#8220;tight&#8221; and will block your file uploads above 1MB I think , max POST attributes , max request size , any many other things.</p>
<p>Using details from this post you should be able to modify them to get the php-cli and php-fcm binarires but remember that each of those binaries needs to be compiled with separate settings (you cant compile all binaries at once) and compiling an apache 2 module is a pain <img src='http://blog.gemcoders.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>If you have any problems with the installation , please leave a comment below <img src='http://blog.gemcoders.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gemcoders.com/2011/08/17/fastcgi-php-5-3-6-compilation-ubuntu-8-04/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web Development</title>
		<link>http://blog.gemcoders.com/2011/07/25/web-development/</link>
		<comments>http://blog.gemcoders.com/2011/07/25/web-development/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 19:47:27 +0000</pubDate>
		<dc:creator>Pawel Barcik</dc:creator>
				<category><![CDATA[blog info]]></category>

		<guid isPermaLink="false">http://blog.gemcoders.com/?p=1</guid>
		<description><![CDATA[Welcome to the web development blog of Gem Coders developer. The purpose of this blog is to gather all the practical knowledge about web development in php and ruby gained during long days spent on various projects. As I cant guarantee a high quality English in my posts ( English is not my native language) [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to the web development blog of <a title="web development in Manchester" href="http://gemcoders.co.uk" target="_blank">Gem Coders</a> developer.</p>
<p>The purpose of this blog is to gather all the practical knowledge about <a title="web development in Manchester" href="http://gemcoders.co.uk" target="_blank">web development in php and ruby</a> gained during long days spent on various projects.</p>
<p>As I cant guarantee a high quality English in my posts ( English is not my native language) , please feel free to submit any comments regarding English grammar <img src='http://blog.gemcoders.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>I will try to provide best practical solutions known to me, to various system design and server setup problems.</p>
<p>I hope you will enjoy it <img src='http://blog.gemcoders.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gemcoders.com/2011/07/25/web-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

