<?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>Darren O&#039;Neill &#187; MVC</title>
	<atom:link href="http://www.darrenoneill.co.uk/tag/mvc/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.darrenoneill.co.uk</link>
	<description></description>
	<lastBuildDate>Fri, 09 Dec 2011 17:27:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Custom error pages in CakePHP</title>
		<link>http://www.darrenoneill.co.uk/custom-error-pages-in-cakephp/</link>
		<comments>http://www.darrenoneill.co.uk/custom-error-pages-in-cakephp/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 16:28:09 +0000</pubDate>
		<dc:creator>Darren</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://darrenoneill.co.uk/?p=318</guid>
		<description><![CDATA[I needed to create some custom error handling functionality on a CakePHP project I was working on a little while ago.]]></description>
			<content:encoded><![CDATA[<p>I needed to create some custom error handling functionality on a CakePHP project I was working on a little while ago. The site URL contained tracking variables and I didn&#8217;t want them to be lost if the people linking to the site got the URL or their individual tracking codes slightly wrong and were in turn redirected to domain.com/pages/home.</p>
<p>I could have created the template error404.ctp under /views/errors/ and written any URL parsing functionality there but coding any PHP logic in a HTML template is not recommended in the MVC framework paradigm. It is worth noting that CakePHP allows you to create the following error templates under /views/errors/ that are great if you just want custom error pages without the need for any PHP code:<br />
<code>error404.ctp<br />
missing_action.ctp<br />
missing_component_class.ctp<br />
missing_component_file.ctp<br />
missing_connection.ctp<br />
missing_controller.ctp<br />
missing_helper_class.ctp<br />
missing_helper_file.ctp<br />
missing_layout.ctp<br />
missing_model.ctp<br />
missing_scaffolddb.ctp<br />
missing_table.ctp<br />
missing_view.ctp<br />
private_action.ctp<br />
scaffold_error.ctp<br />
</code></p>
<p>As I did have a requirement to write some PHP code I created the file app_error.php under the root directory:<br />
<code><br />
class AppError extends ErrorHandler {<br />
public function error404($arg) {<br />
// If someone arrives here - let's keep the tracking codes<br />
$url = $arg['url'];<br />
$url_string = "";<br />
// ...<br />
$this-&gt;controller-&gt;redirect("/pages/mainpage/" . $url_string);<br />
exit();<br />
}<br />
}<br />
</code><br />
As can be seen, you just need to create a function named the same as the error. In this example I am not using the error404.ctp template after processing, instead redirecting to another static page with the tracking codes appended to the end of the URL.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.darrenoneill.co.uk/custom-error-pages-in-cakephp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

