<?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>Development Cycle &#187; PHP</title>
	<atom:link href="http://www.development-cycle.com/category/programming/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.development-cycle.com</link>
	<description>Binary Bits &#38; Pieces</description>
	<lastBuildDate>Fri, 04 May 2012 05:21:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Magic constant not working with require_once</title>
		<link>http://www.development-cycle.com/2012/03/dir-magic-constant-not-working/</link>
		<comments>http://www.development-cycle.com/2012/03/dir-magic-constant-not-working/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 23:29:50 +0000</pubDate>
		<dc:creator>Anthony Mills</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Constant]]></category>
		<category><![CDATA[Debugging]]></category>

		<guid isPermaLink="false">http://www.development-cycle.com/?p=539</guid>
		<description><![CDATA[Its funny when a new feature is added to your language of choice how quickly it gets embraced and used within your code. Today upon uploading some code to a clients shared hosting environment I was greeted by the following error: Uploading a file to display phpinfo() I was able to ascertain the server was [...]]]></description>
			<content:encoded><![CDATA[<p>Its funny when a new feature is added to your language of choice how quickly it gets embraced and used within your code. Today upon uploading some code to a clients shared hosting environment I was greeted by the following error:</p>
<p><a href="http://www.development-cycle.com/wp-content/uploads/2012/03/magic_constant_error.png"><img class="aligncenter size-full wp-image-543" title="magic_constant_error" src="http://www.development-cycle.com/wp-content/uploads/2012/03/magic_constant_error.png" alt="" width="450" height="47" /></a></p>
<p>Uploading a file to display phpinfo() I was able to ascertain the server was running PHP 5.2.17. But after a bit of searching I found the __DIR__ magic constant was not added to PHP until 5.3.</p>
<p>Ends up if your code is going to run on older installs the best solution is to replace __DIR__ with dirname(__FILE__) this provides the same functionality as using the __DIR__ magic constant but works with versions of PHP from 4.0.2.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.development-cycle.com/2012/03/dir-magic-constant-not-working/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Anonymizing CURL Scripts With TOR &amp; Polipo</title>
		<link>http://www.development-cycle.com/2011/08/anonymizing-curl-scripts-with-tor-polipo/</link>
		<comments>http://www.development-cycle.com/2011/08/anonymizing-curl-scripts-with-tor-polipo/#comments</comments>
		<pubDate>Wed, 10 Aug 2011 10:45:09 +0000</pubDate>
		<dc:creator>Anthony Mills</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[CURL]]></category>
		<category><![CDATA[Polipo]]></category>
		<category><![CDATA[Proxy]]></category>
		<category><![CDATA[TOR]]></category>

		<guid isPermaLink="false">http://www.development-cycle.com/?p=511</guid>
		<description><![CDATA[Last week I received a typical run of the mill phishing email littered with the usual bad Engrish making the instructions far from believable but being bored I decided to take a look at the link they were pushing. They had created a believable enough looking Paypal form asking clueless punters to enter their credit [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" title="TOR Logo" src="http://www.development-cycle.com/files/u1/tor_logo.png" alt="" width="200" height="127" />Last week I received a typical run of the mill phishing email littered with the usual bad Engrish making the instructions far from believable but being bored I decided to take a look at the link they were pushing.</p>
<p>They had created a believable enough looking Paypal form asking clueless punters to enter their credit card details in order to avoid having their account being suspended. After playing around with the form for <a title="Firefox Web Development Extension" href="http://getfirebug.com/" target="_blank">awhile in Firebug</a> I decided to create a quick script to poison their data by submitting a new fake 16 digit VISA number along with random card holder name, CVV number and expiry date every couple of seconds.</p>
<p>After running this script for half an hour I decided that the script while it did the job would be a lot better if the posted data was coming from an anonymous IP address. Here I will run you through the process of setting up TOR &amp; Polipo on a machine to add an element of anonymity to the data being sent and received by your CURL based script using.<br />
<span id="more-511"></span><br />
<strong>Installation &amp; Configuration</strong><br />
I am going to use Debian 6 in my examples although getting everything working on your distro of choice shouldn&#8217;t be too complicated.</p>
<p><em>apt-get update</em><br />
<em> apt-get install tor polipo</em></p>
<p>TOR is very easy to use and should straight run out of the box without any configuration, but if you plan on running Polipo on a different box to the TOR service or want to run the service on a different port to the default 9050 you will need to edit the config file at /etc/tor-tsock.conf.</p>
<p>The Polipo configuration is a little more in-depth with a few changes that will have to be made so that the service can forward incoming requests to TOR. Edit the Polipo config file:</p>
<p><em>pico /etc/polipo/config</em></p>
<p>Uncomment line 17 with the &#8220;<em>proxyAddress&#8221;</em> directive and add the external IP address of your machine, mine is set to:</p>
<p><em>proxyAddress = &#8220;192.168.20.123&#8243;</em></p>
<p>Go down to line 23 uncomment the &#8220;<em>allowedClients</em>&#8221; directive and edit to suit your needs in my case its:</p>
<p><em>allowedClients = 127.0.0.1, 192.168.20.0/24</em></p>
<p>Also edit line 40 with the directive <em>&#8220;socksParentProxy&#8221;</em> and change it to point at your TOR service mine is:</p>
<p><em>socksParentProxy = &#8220;localhost:9050&#8243;</em></p>
<p>Uncomment line 41 with the <em>&#8220;socksProxyType</em>&#8221; directive and also uncomment lines 115 &amp; 116 for a bit more security.</p>
<p>Restart the Polipo service so your changes to the configuration file take effect:</p>
<p><em>/etc/init.d/polipo restart</em></p>
<p><strong>Proxy Testing</strong></p>
<p>Its now time to test the set-up and see if its working correctly. I find this test is performed easiest using a browser, simply configure your browser to use your Polipo proxy and visit the site <a title="Find Out Your Current IP Address" href="http://www.whatismyip.com/" target="_blank">whatismyip.com</a>. With any luck you will appear to be coming from a completely different IP to your normal network gateway address.</p>
<p><em>Protip:</em> If you want to use the proxy for anonymous browsing as well, I recommend using the <a title="Foxy Proxy Firefox Plugin" href="https://addons.mozilla.org/en-US/firefox/addon/foxyproxy-standard/" target="_blank">Foxy Proxy plugin for Firefox as it makes switching between</a> your normal gateway and proxies a breeze.</p>
<p><strong>Configuring CURL</strong><br />
By now you should have a configured and tested proxy service now its just a case of fo configuring your script to use the proxy. To use a proxy from CURL you simply need to add the <em>CURLOPT_PROXY</em> option to your script with the IP address and port of your proxy service i.e</p>
<p><em>curl_setopt($ch, CURLOPT_PROXY, &#8216;http://192.168.20.123:8123&#8242;);</em></p>
<p><strong>Further Reading:</strong><br />
<a title="Polipo Homepage" href="http://www.pps.jussieu.fr/~jch/software/polipo/" target="_blank">Polipo Homepage</a><br />
<a title="The Onion Router Project Homepage" href="https://www.torproject.org/" target="_blank">TOR Homepage</a></p>
<p><strong>Related Reading:</strong><br />
<a title="Installing TOR Onion Router On Ubuntu 8.0.4 (Hardy Heron)" href="http://www.development-cycle.com/2008/07/tor-on-ubuntu-hardy/">Installing TOR On Ubuntu 8.04</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.development-cycle.com/2011/08/anonymizing-curl-scripts-with-tor-polipo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Logging PHP Errors For Production Environments</title>
		<link>http://www.development-cycle.com/2011/07/logging-php-errors-for-production-environments/</link>
		<comments>http://www.development-cycle.com/2011/07/logging-php-errors-for-production-environments/#comments</comments>
		<pubDate>Mon, 18 Jul 2011 01:16:41 +0000</pubDate>
		<dc:creator>Anthony Mills</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[Error Handling]]></category>

		<guid isPermaLink="false">http://www.development-cycle.com/?p=423</guid>
		<description><![CDATA[Good security practices dictate PHP should be configured to never display error messages and notices to screen in a production environment due to its potential to reveal information about your server and application setup. One solution is to enable error logging on the server by setting the log_errors attribute to 1 in your php.ini and [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-424" title="PHP Logo" src="http://www.development-cycle.com/wp-content/uploads/2011/07/php_logo.png" alt="" width="200" height="105" />Good security practices dictate PHP should be configured to never display error messages and notices to screen in a production environment due to its potential to reveal information about your server and application setup. One solution is to enable error logging on the server by setting the <em>log_errors</em> attribute to 1 in your php.ini and reloading Apache. When active by default all errors will be sent to the Apache error log and will appear similar to the line below, unless a different path has been set in the php.ini configuration file using the <em>error_log</em> directive.</p>
<p><span id="more-423"></span><div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.development-cycle.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://www.development-cycle.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.development-cycle.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.development-cycle.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="text" style="font-family:monospace;">[Mon Jul 16 10:17:31 2011] [error] [client 58.96.56.198] PHP Fatal error:
Uncaught SoapFault exception: [sf:INVALID_LOGIN] INVALID_LOGIN: Invalid
username, user not active in /var/www/myapp/includes/thirdparty/developerforce/soapclient/SforceBaseClient.
php:162</pre></div></div></p>
<p>Sometimes you may not have permission to edit the php.ini file or don&#8217;t want to effect the error reporting for other applications that live on the same box. This leaves you the option of changing the error reporting setting temporarily either in a .htaccess file or in the script itself. Telling PHP to log errors at runtime is very easy to achieve simply add the line below to your script, be warned though this approach is not an optimal solution in most situations, if there is a parse error in your script the directive will not be run and no errors will be logged.</p>
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.development-cycle.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://www.development-cycle.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.development-cycle.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.development-cycle.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><pre class="text" style="font-family:monospace;">ini_set(&quot;log_errors&quot;, 1);</pre></div></div>
<p>A better option is to set the logging directive in a .htaccess file if your server is configured to allow their use. Simply open up your .htaccess files or create a new one in the directory of your application if you don&#8217;t have one already and add a line with the <em>log_errors</em> directive and save:</p>
<div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.development-cycle.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img border="0" style="border: 0 none" src="http://www.development-cycle.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.development-cycle.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.development-cycle.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><pre class="text" style="font-family:monospace;">php_value log_errors 1</pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.development-cycle.com/2011/07/logging-php-errors-for-production-environments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework 1.9.6</title>
		<link>http://www.development-cycle.com/2009/11/zend-framework-1-9-6/</link>
		<comments>http://www.development-cycle.com/2009/11/zend-framework-1-9-6/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 12:23:26 +0000</pubDate>
		<dc:creator>Anthony Mills</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.development-cycle.com/?p=197</guid>
		<description><![CDATA[Zend Framework 1.9.6 has been released today with over 60 bug fixed included, most of which where found during the bug hunt days last week. The official Zend Framework site reports this release is planned to be the last before the 1.10.0 release. The new release can be downloaded here, and a full list of [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-198" title="zf_logo_white" src="http://www.development-cycle.com/wp-content/uploads/2009/11/zf_logo_white.jpg" alt="zf_logo_white" width="130" height="58" />Zend Framework 1.9.6 has been released today with over 60 bug fixed included, most of which where found during the bug hunt days last week. The official Zend Framework site reports this release is planned to be the last before the 1.10.0 release.</p>
<p>The new release can be downloaded <a rel="nofollow" href="http://framework.zend.com/download/latest" target="_blank">here</a>, and a full list of the changes in this release the <a href="http://framework.zend.com/changelog/1.9.6" target="_blank" rel="nofollow">change log can be found here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.development-cycle.com/2009/11/zend-framework-1-9-6/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting Baked With CakePHP</title>
		<link>http://www.development-cycle.com/2008/09/learn-cakephp/</link>
		<comments>http://www.development-cycle.com/2008/09/learn-cakephp/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 22:46:46 +0000</pubDate>
		<dc:creator>Anthony Mills</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<p><strong>What Is CakePHP?</strong></p>
<p>CakePHP is a PHP open source rapid development framework that was born in 2005, it is distributed under an MIT licence and has a very active community. So of its other features include:</p>]]></description>
			<content:encoded><![CDATA[<p><strong>What Is CakePHP?</strong></p>
<p>CakePHP is a PHP open source rapid development framework that was born in 2005, it is distributed under an MIT licence and has a very active community. So of its other features include:</p>
<ul>
<li>Compatibility with PHP4 and PHP5</li>
<li>Integrated <a title="CRUD Create Read Update and Delete" href="http://en.wikipedia.org/wiki/Create,_read,_update_and_delete">CRUD</a> for database interaction and simplified queries</li>
<li>Model View Controller (<a title="Model View Controller (MVC)" href="http://en.wikipedia.org/wiki/Model-view-controller">MVC</a>) Architecture</li>
<li>Request dispatcher with good looking, custom URLs</li>
<li>Built-in Validation</li>
<li>Fast and flexible templating (PHP syntax, with helpers)</li>
<li>View Helpers for AJAX, Javascript, HTML Forms and more</li>
<li>Security, Session, and Request Handling Components</li>
<li>Flexible access control lists</li>
<li>Data Sanitation</li>
<li>Flexible View Caching</li>
</ul>
<p>In this post i will run the reader through the process of setting up CakePHP and then creating a simple notice board application to demonstrate the simplicity of writing an application with cake.</p>
<p><strong>Installing CakePHP</strong></p>
<p>Download the latest copy of CakePHP from <a title="The official home of the CakePHP framework" href="http://www.cakephp.org">www.CakePHP.org</a> uncompress and place in the root directory of your web server. Check that the <a href="http://httpd.apache.org/">Apache</a> &lt;directory&gt; option for the root directory contains the AllowOverride option and it is set to &#8220;ALL&#8221; i.e</p>
<p>&lt;Directory /mypath/tocakephp/&gt;<br />
Options Indexes FollowSymLinks MultiViews<br />
AllowOverride All<br />
Order allow,deny<br />
allow from all<br />
&lt;/Directory&gt;</p>
<p>You must also ensure that Apache is using the <a href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html"><em>rewrite mod</em></a><a> to enable this on my Ubuntu based server system i used the command a2enmod rewrite. After all your changes to the Apache configuration have been made restart the Apache service so the changes take affect.</a></p>
<p><a> </a></p>
<p><a>Depending on how you configured Apache you may run into some trouble with the rewrite functionality, have a look at the web server URL in a browser, if the CakePHP page you see is missing its CSS and images something is amiss. You have two options with how you want to move forward from this point, you can uncomment line 40 of the CakePHP config file (app/config/core.php) which will work around the malfunctioning </a><a href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html"><em>rewrite mod</em></a><a> plugin. Or you can look at this page on the </a><a title="CakePHP tips on getting mod_rewrite working on your server" href="http://book.cakephp.org/view/333/A-Note-on-mod_rewrite">CakePHP site</a>, which has some pointers on fixing the problem properly.</p>
<p>Also you must make sure Apache has write access to the app/tmp directory and its sub folders before. A new MySQL database named notice_board will have to be created using PHPmyadmin or similar to hold the data for our sample application.<br />
After this is done the file app/config/database.php.default needs to be renamed to app/config/database.php. Using a text editor the database parameters in the file then need to be changed to match your MySQL setup and the changes saved.</p>
<p><img title="CakePHP after initial setup" src="/files/images/cake/cake1.png" alt="CakePHP after initial setup" width="411" height="235" /></p>
<p><strong>Baking Your First Application</strong></p>
<p>Now the framework is installed we can start work on our first CakePHP application its going to be a simple notice board, it wont have all the bells and whistles but it will show you how quickly, and easily some tasks can be accomplished using cake.<br />
First up you will need to make a table in the database you created earlier to hold our notices.</p>
<p>CREATE TABLE `notice_board`.`notices` (<br />
`id` INT( 10 ) NOT NULL AUTO_INCREMENT ,<br />
`title` VARCHAR( 255 ) NOT NULL ,<br />
`content` TEXT NOT NULL ,<br />
`created` VARCHAR( 30 ) NOT NULL ,<br />
`modified` VARCHAR( 30 ) NOT NULL ,<br />
PRIMARY KEY ( `id` )<br />
);</p>
<p><em><strong>** Note:</strong></em> it is CakePHP convention to use plural names when naming database tables. All tables should also have a field named &#8220;id&#8221; as the primary key.</p>
<p><strong>Creating The Model</strong></p>
<p>In CakePHP each database table should have its own model, this model is basically just a class and is used to access and modify the data stored within the table. To create a model for the notices table create a file named notice.php in the app/models folder. In this file enter:</p>
<p>&lt;?php<br />
class Notice extends AppModel {<br />
var $name=&#8217;Notice&#8217;;<br />
}<br />
?&gt;</p>
<p>You can see from the code above the Entry calls extends the AppModel class, in CakePHP all models extend this class.</p>
<p><em><strong>**Note:</strong></em> It is also a CakePHP convention that the model class its file name is a singular version of database table name.</p>
<p><strong>Creating The Controller</strong></p>
<p>The controller is a piece of code that decides what has to happen within an MVC application. Every model in an application needs an associated controller. Creating a controller for the notice board application is very similar to creating the model. Just create a new file named notices_controller.php in the app/controllers directory.</p>
<p>In this file enter the following code:</p>
<p>&lt;?php<br />
class NoticesController extends AppController {<br />
var $name = &#8216;Notices&#8217;;<br />
function index() {<br />
$this-&gt;set(&#8216;notices&#8217;, $this-&gt;Notice-&gt;findAll());<br />
}<br />
}<br />
?&gt;</p>
<p>The addition of the index function is a method to give our controller some functionality in this case to display all of the notices stored in the database.<br />
<em><strong><br />
**Note:</strong></em> It is CakePHP convention that controller names are plurals of the model name.</p>
<p>Â</p>
<p><strong>Creating A View</strong></p>
<p>We have a model, a database and a controller so now we need a view to display our hard work to the end user. Create a new directoryÂ  called notices in the folder named app/views. Now create a file within the newly created directory called index.thtml containing the following code:</p>
<p>&lt;h2&gt;Notice Board&lt;/h2&gt;<br />
&lt;p&gt;&lt;?PHP echo $HTML-&gt;link(&#8216;Add New Notice&#8217;, &#8216;/notices/add&#8217;); ?&gt;&lt;/p&gt;<br />
&lt;div style=&#8221;height: 10px;&#8221;&gt;&lt;/div&gt;<br />
&lt;?PHP if(empty($notices)) : ?&gt;<br />
This notice board currently has no notices to display.<br />
&lt;?PHP<br />
else:<br />
foreach ($notices as $notice):<br />
echo &#8216;&lt;b&gt;Title:&lt;/b&gt; &#8216; . $notice['Notice']['title'] . &#8216;&lt;br&gt;&#8217;;<br />
echo $notice['Notice']['content'] . &#8216;&lt;br&gt;&#8217;;<br />
echo &#8216;&lt;b&gt;Created: &lt;/b&gt;&lt;i&gt;&#8217; . $notice['Notice']['created'] . &#8216;&lt;/i&gt;&lt;br&gt;&#8217;;<br />
echo $HTML-&gt;link(&#8216;Delete&#8217;, &#8220;/notices/delete/{$notice['Notice']['id']}&#8221;, null, &#8216;Are you sure?&#8217;Â  );<br />
echo &#8216;&lt;br&gt;&lt;div style=&#8221;height: 10PX;&#8221;&gt;&lt;/div&gt;&#8217;;<br />
endforeach;<br />
endif;<br />
?&gt;</p>
<p>**Note: The 1.2 version of CakePHP will use the file extension .ctp as opposed to the extension .thtml usedforÂ  &#8220;views&#8221; in the earlier versions.</p>
<p>Now if you aim your browser at your server&#8217;s url with the trailing name &#8220;notices&#8221; i.e http://mysever.com/notices, you should be able to now see that we are making some positive progress with our app.</p>
<p><img title="Viewing The notices on the CakePHP app" src="/files/images/cake/cake2.png" alt="Viewing The notices on the CakePHP app" width="390" height="147" /></p>
<p><strong>Creating New Notices</strong></p>
<p>Since we have laid out the ability to view notices its time to add some functionality to the controller so a user can actually post notices to the board. To achieve this you will need to edit the notices_controller.PHP and append an add function, so the files contents look like this:</p>
<p>&lt;?PHP<br />
class NoticesController extends AppController {<br />
var $name = &#8216;Notices&#8217;;<br />
function index() {<br />
$this-&gt;set(&#8216;notices&#8217;, $this-&gt;Notice-&gt;findAll());<br />
}</p>
<p>function add() {<br />
if (!empty($this-&gt;data)) {<br />
if ($this-&gt;Notice-&gt;save($this-&gt;data)) {<br />
$this-&gt;flash(&#8216;Your notice has been posted.&#8217;,'/notices&#8217;);<br />
}<br />
}<br />
}<br />
}<br />
?&gt;</p>
<p>Now create a template named app/views/add.thtml with the code below for the user to enter the details of a new notice.</p>
<p>&lt;h2&gt;Create Notice&lt;/h2&gt;<br />
&lt;form method=&#8221;post&#8221; action=&#8221;&lt;?PHP echo $HTML-&gt;url(&#8216;/notices/add&#8217;)?&gt;&#8221;&gt;<br />
&lt;div align=&#8221;center&#8221;&gt;<br />
&lt;p&gt;<br />
Notice Title:<br />
&lt;?PHP echo $HTML-&gt;input(&#8216;Notice/title&#8217;, array(&#8216;size&#8217; =&gt; &#8217;40&#8242;))?&gt;<br />
&lt;?PHP echo $HTML-&gt;tagErrorMsg(&#8216;Notice/title&#8217;, &#8216;A notice title is required.&#8217;) ?&gt;<br />
&lt;/p&gt;</p>
<p>&lt;p&gt;<br />
Notice Body:<br />
&lt;?PHP echo $HTML-&gt;textarea(&#8216;Notice/content&#8217;, array(&#8216;rows&#8217;=&gt;&#8217;10&#8242;)) ?&gt;<br />
&lt;?PHP echo $HTML-&gt;tagErrorMsg(&#8216;Notice/content&#8217;, &#8216;Your notice needs some content.&#8217;) ?&gt;<br />
&lt;/p&gt;</p>
<p>&lt;p&gt;<br />
&lt;?PHP echo $HTML-&gt;submit(&#8216;Create Notice&#8217;) ?&gt;<br />
&lt;/p&gt;<br />
&lt;/div&gt;<br />
&lt;/form&gt;</p>
<p><img title="Adding new notices to the CakePHP App" src="/files/images/cake/cake4.png" alt="Adding new notices to the CakePHP App" width="408" height="263" /></p>
<p><strong>Form Validation<br />
</strong></p>
<p>Since the application has a form to accept data from a user the entered data will have to be validated, one of CakePHP&#8217;s strong points is its built in validation functionality removing a lot of pain for developers.<br />
To handle the validation of our new notice you need to go back and edit the entries model (app/models/notice.PHP) and append a validate array so the file looks like this:</p>
<p>&lt;?PHP<br />
class Notice extends AppModel {<br />
var $name=&#8217;Notice&#8217;;<br />
var $validate = array(<br />
&#8216;title&#8217; =&gt; VALID_NOT_EMPTY,<br />
&#8216;body&#8217; =&gt; VALID_NOT_EMPTY<br />
);<br />
}<br />
?&gt;</p>
<p><strong>Deleting Existing Notices</strong></p>
<p>Now notices can be added to the board, it makes sense to add functionality supporting the deletion of a notice. To achieve this we need to add a new function to our controller so the delete link on the index page works properly. Open the controller file back up and add a delete function so the file contents are the same as below:</p>
<p>&lt;?PHP<br />
class NoticesController extends AppController {<br />
var $name = &#8216;Notices&#8217;;<br />
function index() {<br />
$this-&gt;set(&#8216;notices&#8217;, $this-&gt;Notice-&gt;findAll());<br />
}</p>
<p>function add() {<br />
if (!empty($this-&gt;data)) {<br />
if ($this-&gt;Notice-&gt;save($this-&gt;data)) {<br />
$this-&gt;flash(&#8216;Your notice has been posted.&#8217;,'/notices&#8217;);<br />
}<br />
}<br />
}</p>
<p>function delete($id) {<br />
$this-&gt;Notice-&gt;del($id);<br />
$this-&gt;flash(&#8216;The selected notice has been deleted.&#8217;, &#8216;/notices&#8217;);<br />
}</p>
<p>}<br />
?&gt;</p>
<p>You should now be the proud owner of your first working CakePHP web application!</p>
<p style="text-align: center;"><img title="Notice Views CakePHP Notice Board" src="/files/images/cake/cake3.png" alt="Notice Views CakePHP Notice Board" width="343" height="278" /></p>
<p><strong>Further Reading</strong></p>
<p>CakePHP (Official Site)<br />
<a title="The Official Home Of CakePHP" href="http://www.cakephp.org/">http://www.cakephp.org/</a></p>
<p>A Run Down On The Conventions In CakePHP<br />
<a title="CakePHP conventions" href="http://book.cakephp.org/view/22/CakePHP-Conventions">http://book.cakephp.org/view/22/CakePHP-Conventions</a></p>
<p>Understanding MVC (On the CakePHP site)<br />
<a title="CakePHP overview of MVC design pattern" href="http://book.cakephp.org/view/11/Overview">http://book.cakephp.org/view/11/Overview</a></p>
<p>Model View Controller &#8211; Background, History etc on Wikipedia<br />
<a title="Wikipedia entry on the Model View Controller (MVC) design pattern" href="http://en.wikipedia.org/wiki/Model-view-controller">http://en.wikipedia.org/wiki/Model-view-controller</a></p>
<p>Â</p>
<p>Â</p>
]]></content:encoded>
			<wfw:commentRss>http://www.development-cycle.com/2008/09/learn-cakephp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: www.development-cycle.com @ 2012-05-19 20:50:03 -->
