<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.1" -->
<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/"
	>

<channel>
	<title>Web Expose</title>
	<link>http://webexpose.org</link>
	<description>views from the changing web</description>
	<pubDate>Tue, 13 May 2008 13:36:55 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1</generator>
	<language>en</language>
			<item>
		<title>Subversion 1.5 merge-tracking&#8230; looks awesome</title>
		<link>http://webexpose.org/2008/05/13/subversion-15-merge-tracking-looks-awesome/</link>
		<comments>http://webexpose.org/2008/05/13/subversion-15-merge-tracking-looks-awesome/#comments</comments>
		<pubDate>Tue, 13 May 2008 13:36:55 +0000</pubDate>
		<dc:creator>michael</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://webexpose.org/2008/05/13/subversion-15-merge-tracking-looks-awesome/</guid>
		<description><![CDATA[
While Subversion 1.5 doesn’t make it merging as easy as a system like Git or Mercurial, it certainly solves common points of pain. As a famous quote goes, “it makes easy things easy, and hard things possible.” Subversion is now beginning to match features in larger, commercial tools such as Clearcase and Perforce.

Read more at [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>
While Subversion 1.5 doesn’t make it merging as easy as a system like Git or Mercurial, it certainly solves common points of pain. As a famous quote goes, “it makes easy things easy, and hard things possible.” Subversion is now beginning to match features in larger, commercial tools such as Clearcase and Perforce.
</p></blockquote>
<p>Read more at the original post to see how easy this is: <a href="http://blog.red-bean.com/sussman/?p=92">Subversion 1.5 merge-tracking in a nutshell</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://webexpose.org/2008/05/13/subversion-15-merge-tracking-looks-awesome/feed/</wfw:commentRss>
		</item>
		<item>
		<title>CakePHP Routes</title>
		<link>http://webexpose.org/2007/05/09/cakephp-routes/</link>
		<comments>http://webexpose.org/2007/05/09/cakephp-routes/#comments</comments>
		<pubDate>Wed, 09 May 2007 14:05:35 +0000</pubDate>
		<dc:creator>michael</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://webexpose.org/2007/05/09/cakephp-routes/</guid>
		<description><![CDATA[The documentation covering routes in CakePHP is a bit confusing, and doesn&#8217;t quite cover how you can you use paths in the URL as method parameters. I&#8217;ll cover how I used them in a recent app in this short article.
Routing in CakePHP is similar to using Apache&#8217;s mod_rewrite to give you pretty URLS, for example, [...]]]></description>
			<content:encoded><![CDATA[<p>The documentation covering routes in CakePHP is a bit confusing, and doesn&#8217;t quite cover how you can you use paths in the URL as method parameters. I&#8217;ll cover how I used them in a recent app in this short article.</p>
<p>Routing in CakePHP is similar to using Apache&#8217;s mod_rewrite to give you pretty URLS, for example, mapping:</p>
<pre><code>   http://server/item/1</code> to </code>http://server/items.php?id=1</code></pre>
<p>They are used in Cake so that you don&#8217;t require mod_rewrite/Apache to achieve such cleaned-up URLS.</p>
<p><strong>Cake&#8217;s route documentation</strong> (look under <strong>Section 3</strong>)<br />
<a href='http://manual.cakephp.org/chapter/configuration' title='CakePHP Configuration'>http://manual.cakephp.org/chapter/configuration</a></p>
<p>In my application I wanted to get rid of the <code>controller/action</code> convention and rather have URLs like <code>http://server/about</code> and <code>http://server/contact</code> that are both served by one controller called <strong>Pages</strong></p>
<p>My route file looks like this:</p>
<pre><code> 1   $Route->connect('/', array('controller' => 'pages'));
 2   $Route->connect('/:action/*', array('controller' => 'pages',
      'action' => ':action'));</code></pre>
<p>Line 1 says that any request for the root document should be handled by the <strong>Pages</strong> controller, and since no action was specified, the method will default to <code>index()</code>.</p>
<p>The second line catches one or more path parameters and assigns the first one to <code>:action</code>, and the rest are caught by the asterisk (<code>*</code>) and passed along to the controller.</p>
<p><strong>Example</strong></p>
<pre>   <code>http://server/about/cars/ford</code>
   <strong>:action</strong> => &#8216;about&#8217;
   <strong>parameters</strong> => &#8216;cars&#8217;, &#8216;ford&#8217;
</pre>
<p>We then assign this route to the <strong>Pages</strong> controller, and to the action that was specified as the first path variable.</p>
<p>Inside <code>pages_controller.php</code>, we have something like this:</p>
<pre><code>   function about($page = 'default', $type = null) {
      //code dealing with parameters
      //error checking etc.
      $this->render($chosen_page);
   }</code></pre>
<p>In our example above, <code>$page</code> will equal &#8216;cars&#8217; and <code>$type</code> will equal &#8216;ford&#8217;.</p>
<p>In this way you can have one controller serving a variety of different pages, out&#8217;ve one action - instead of the usual one action per page convention.</p>
]]></content:encoded>
			<wfw:commentRss>http://webexpose.org/2007/05/09/cakephp-routes/feed/</wfw:commentRss>
		</item>
		<item>
		<title>10 Ways to get on to Digg&#8217;s frontpage</title>
		<link>http://webexpose.org/2007/04/03/10-ways-to-get-on-to-diggs-frontpage/</link>
		<comments>http://webexpose.org/2007/04/03/10-ways-to-get-on-to-diggs-frontpage/#comments</comments>
		<pubDate>Tue, 03 Apr 2007 13:11:54 +0000</pubDate>
		<dc:creator>michael</dc:creator>
		
		<category><![CDATA[General]]></category>

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

		<guid isPermaLink="false">http://webexpose.org/2007/04/03/10-ways-to-get-on-to-diggs-frontpage/</guid>
		<description><![CDATA[Digg is the new Slashdot, and whilst getting digged might not bring your site down like a true slashdotting, it is far cooler and carries more interweb credibility. So here are the top ten ways to get your site onto the frontpage of Digg:

Buy your diggs
The easiest way: create a fake website/blog and fill it [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://digg.com' title='Digg'>Digg</a> is the new <a href='http://slashdot.org' title='Slashdot'>Slashdot</a>, and whilst getting digged might not bring your site down like a true slashdotting, it is far cooler and carries more interweb credibility. So here are the top ten ways to get your site onto the frontpage of Digg:</p>
<ol>
<li><strong>Buy your diggs</strong><br />
The easiest way: create a fake website/blog and fill it with drivel and useless rambling content. Now find a pay service that guarantees you diggs through a sneaky network of paid-for clicks. Make sure your site is loaded with Google Ad&#8217;s in order to try<br />
make up the money you spent on getting digged (this probably won&#8217;t happen).
</li>
<li><strong>Post a story about how you got digged using a paid service</strong><br />
After completing step 1, ensure that you create another article/website detailing how you defrauded Digg by using the sneaky click service. You are guaranteed to be digged again.
</li>
<li><strong>Get a story digged and then post a follow up story about how you survived the digging</strong><br />
This is a bit of a conundrum since to get digged you&#8217;ll have to have been digged previously. Perhaps use number 1 and 2 above. Once your host has survived/crumbled the digging, post about how it happened, what happened, and which affiliate host you really recommend that every reader signs up with. Don&#8217;t forget the your affiliate ID in those referring links! (also known as an advertorial.)
</li>
<li><strong>The best &lt;subject&gt; picture you&#8217;ll see today</strong><br />
Spend some time browsing those lame college humour websites and find some random picture that was funny in 1998 and then create a new post on your blog hot-linking straight to the image with an additional 5 word caption written by you. Submit it as a new story on Digg with the headline, &#8220;The best &lt;subject&gt; picture you&#8217;ll see today&#8221;. Alternatively find pictures of anything happening in slow motion (milk hitting coffee for instance) and post that - additional points if you manage to get pictures that everyone saw last year digged again.
</li>
<li><strong>Discuss how Digg is flawed</strong><br />
Write an article discussing how digg is flawed and the users are stupid. Include examples of spam posts that made it to the front page and also add details of a giant conspiracy that is ruining the internet for everyone.
</li>
<li><strong>Random non-expert advice</strong><br />
Find a blog written by a 12 year old who professes to be an expert in some field related to computers. Take his/her word as gospel and repost their article on your blog, and then submit it to Digg as the latest professional advice from some expert. Don&#8217;t worry if they can&#8217;t spell, think straight, or even write articles longer than 20 words, Digg forgives all.
</li>
<li><strong>Create a Top 10 list on absolutely anything</strong><br />
I lied, paying for your diggs isn&#8217;t the easiest way to get onto the front page. Creating a top 10 list of absolutely any subject that enters your head is the easiest way to get onto Digg. Think of something, anything, bananas! Make a 10 point list about banana&#8217;s; even if it isn&#8217;t a TOP 10 list, label it as such. Or steal someone else&#8217;s list and link to it on your site, then submit that. Make sure that at least some of the points are fillers or repeats of previous points.
</li>
<li><strong>Create a Top 5 list on absolutely anything</strong><br />
I lied, paying for your diggs isn&#8217;t the easiest way to get onto the front page. Creating a top 5 list of absolutely any subject that enters your head is the easiest way to get onto Digg. Think of something, anything, bananas! Make a 5 point list about banana&#8217;s; even if it isn&#8217;t a TOP 5 list, label it as such. Or steal someone else&#8217;s list and link to it on your site, then submit that. Make sure that at least some of the points are fillers or repeats of previous points.
</li>
<li><strong>Repost this article on your blog</strong><br />
Easy.
</li>
<li><strong>Write something useful that people would enjoy reading</strong><br />
Haha, no seriously&#8230;
</li>
</ol>
<p><div class="diggbutton"><script type="text/javascript">digg_url = 'http://digg.com/tech_news/Top_10_Ways_to_get_on_to_Digg_s_frontpage';</script><script type="text/javascript" src="http://digg.com/api/diggthis.js"></script></div></p>
]]></content:encoded>
			<wfw:commentRss>http://webexpose.org/2007/04/03/10-ways-to-get-on-to-diggs-frontpage/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Both sides of a quick and simple web service</title>
		<link>http://webexpose.org/2007/04/03/both-sides-of-a-quick-and-simple-web-service/</link>
		<comments>http://webexpose.org/2007/04/03/both-sides-of-a-quick-and-simple-web-service/#comments</comments>
		<pubDate>Tue, 03 Apr 2007 01:48:29 +0000</pubDate>
		<dc:creator>michael</dc:creator>
		
		<category><![CDATA[PHP]]></category>

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

		<guid isPermaLink="false">http://webexpose.org/2007/04/03/both-sides-of-a-quick-and-simple-web-service/</guid>
		<description><![CDATA[To clarify the article title, when I say web service, I mean a piece of software that will receive and send out data via the HTTP protocol. Furthermore, this data is usually transmitted in XML format. I will also call this XML RPC occasionally, but there is also a specification called XML-RPC so things can [...]]]></description>
			<content:encoded><![CDATA[<p>To clarify the article title, when I say web service, I mean a piece of software that will receive and send out data via the HTTP protocol. Furthermore, this data is usually transmitted in XML format. I will also call this XML RPC occasionally, but there is also a specification called <a href='http://en.wikipedia.org/wiki/XML-RPC' title='XML-RPC'>XML-RPC</a> so things can get confusing. Again in summary, this post will describe a very simple way to send and receive method calls and responses using XML and HTTP POST.</p>
<p><strong>Sending your request</strong><br />
This will use the PHP cURL extension, so make sure your PHP is compiled with the correct options. The XML parser later will also use SimpleXML, which needs PHP 5 and the SimpleXML extension.</p>
<p>The following function will submit a query to an arbitrary web server, and also allow you to pass a POST string through to it.</p>
<pre><code>   function cURL($link, $poststring){
        $ch = curl_init();

        curl_setopt ($ch, CURLOPT_URL, $link);
        curl_setopt ($ch, CURLOPT_POST, 1);
        curl_setopt ($ch, CURLOPT_POSTFIELDS, $poststring);
        curl_setopt ($ch, CURLOPT_HEADER, 0);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt ($ch, CURLOPT_TIMEOUT, 15);

        $response = trim(curl_exec ($ch));
        return $response;
   } //cURL</code></pre>
<p>Now, you should decide on a format for your XML requests; we&#8217;ll use something very simple here:</p>
<pre><code>   &lt;?xml version='1.0'?&gt;
   &lt;request&gt;
      &lt;user&gt;Mike&lt;/user&gt;
      &lt;type&gt;getDate&lt;/type&gt;
   &lt;/request&gt;</code></pre>
<p>This will ask another server for the current time, and use basic user name authentication.</p>
<p>To send the request:</p>
<pre><code>   $poststring = "request=$xml";
   $response = cURL('http://server.com/xml.php', $poststring);</code></pre>
<p><strong>Receiving the request</strong><br />
On the other side of the connection we write some code to parse the request (i.e. this is in <code>xml.php</code> hosted on server.com).</p>
<pre><code>   $xml = (isset($_POST['request'])) ? $_POST['request'] : false;
   if (!$xml) { return; }</code></pre>
<p>Now the above XML we sent is stored in the <code>$xml</code> variable. To process it, we can use the following code:</p>
<pre><code>   $obj = simplexml_load_string($xml);

   $error = '';

   if ((string)$obj->user == 'Mike') {
      switch ((string)$obj->type) {
         case 'getDate' :
            $response = "&lt;?xml version='1.0'?&gt;
               &lt;response&gt;
                  &lt;date&gt;".date('l, d F Y at H:i:s', time())."&lt;/date&gt;
               &lt;/response&gt;";
            break;

         default :
            $error = 'Invalid method';
      } //switch
   } else {
      $error = 'Invalid user';
   } //else

   if ($error) {
      print "&lt;?xml version='1.0'?&gt;
         &lt;response&gt;
            &lt;error&gt;$error&lt;/error&gt;
         &lt;/response&gt;";
   } else {
      print $response;
   } //else</code></pre>
<p>After checking the user name the method name is handled, and if it doesn&#8217;t exist on this implementation an error is returned. Printing the XML response is how we pass data back to the server that requested the service - if you look back you&#8217;ll see that the <code>cURL</code> function returns whatever content the URL returned, i.e. our printed XML.</p>
<p>That should be everything, this should of course be expanded into a class or structured methods.</p>
]]></content:encoded>
			<wfw:commentRss>http://webexpose.org/2007/04/03/both-sides-of-a-quick-and-simple-web-service/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Some tidbits</title>
		<link>http://webexpose.org/2007/03/29/some-tidbits/</link>
		<comments>http://webexpose.org/2007/03/29/some-tidbits/#comments</comments>
		<pubDate>Thu, 29 Mar 2007 20:10:25 +0000</pubDate>
		<dc:creator>michael</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://webexpose.org/2007/03/29/some-tidbits/</guid>
		<description><![CDATA[I realise posts have been thin on the ground lately, so here are a few good links to keep you busy. On a related note, I&#8217;m always looking for people who want to write articles on any (web) topic - there are no requirements, as long as you make sense and can spell, then feel [...]]]></description>
			<content:encoded><![CDATA[<p>I realise posts have been thin on the ground lately, so here are a few good links to keep you busy. On a related note, I&#8217;m always looking for people who want to write articles on any (web) topic - there are no requirements, as long as you make sense and can spell, then feel free to write up a tutorial or something cool that you want to show everyone else!</p>
<p><strong>Logging in Javascript</strong><br />
<a href='http://www.alistapart.com/articles/jslogging/' title='JS Logging'>http://www.alistapart.com/articles/jslogging/</a></p>
<p>A good article by the excellent writers at A List Apart. This covers using <code>fvlogger</code> to debug and test your javascript scripts.</p>
<p><strong>15 JS snippets you can&#8217;t live without</strong><br />
<a href='http://www.igglo.co.uk/6/15-javascript-snippets-you-cant-live-without/' title='Snippets'>http://www.igglo.co.uk/6/15-javascript-snippets-you-cant-live-without/</a></p>
<p>This might be a bit of an overstatement, but there are a couple of really cool scripts covered in the article. Otherwise this seems to be a bit of a rehash of previous articles written elsewhere. Check out <a href='http://www.huddletogether.com/projects/lightbox2/' title='lightbox'>Lightbox</a>, and then play around with <a href='http://jquery.com/demo/thickbox/' title='Thickbox'>Thickbox</a>, the JQuery alternative.</p>
<p>I also quite like <code>frequency-decoder</code>&#8217;s <a href='http://www.frequency-decoder.com/2006/10/02/unobtrusive-date-picker-widgit-update' title='Date picker widget'>Date Picker widget</a>.</p>
<p><strong>CSS good habits</strong><br />
<a href='http://www.communitymx.com/content/article.cfm?cid=FAF76&#038;print=true' title='CSS Good Habits'>http://www.communitymx.com/content/article.cfm?cid=FAF76&#038;print=true</a></p>
<p>Lastly, a relatively short post on good CSS coding habits. Useful for people new to web development and CSS.</p>
]]></content:encoded>
			<wfw:commentRss>http://webexpose.org/2007/03/29/some-tidbits/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Spam, lovely spam</title>
		<link>http://webexpose.org/2007/03/21/spam-lovely-spam/</link>
		<comments>http://webexpose.org/2007/03/21/spam-lovely-spam/#comments</comments>
		<pubDate>Wed, 21 Mar 2007 16:13:59 +0000</pubDate>
		<dc:creator>michael</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://webexpose.org/2007/03/21/spam-lovely-spam/</guid>
		<description><![CDATA[Ok, I&#8217;ve had to disable comments on the IE7 for linux post, the amount of spam that&#8217;s coming through is quite insane. Today there were 149 spam comments in my moderation queue. This site alone is eating up a large chunk of bandwidth on my host, I think (note: think) that it&#8217;s due to the [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, I&#8217;ve had to disable comments on the IE7 for linux post, the amount of spam that&#8217;s coming through is quite insane. Today there were 149 spam comments in my moderation queue. This site alone is eating up a large chunk of bandwidth on my host, I think (note: think) that it&#8217;s due to the repeated hits and abuse from spam bots. I&#8217;m going to start looking at blocking hosts in my <code>.htaccess</code> file, but I am not optimistic about it.</p>
<p>If anyone has any suggestions, please comment and let me know. Remember though, I want to deny spambots access to the site completely, so a Wordpress plug-in probably isn&#8217;t what I&#8217;m looking for.</p>
<p>There&#8217;ll be some new articles and tutorials soon, once I have a free minute!</p>
]]></content:encoded>
			<wfw:commentRss>http://webexpose.org/2007/03/21/spam-lovely-spam/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Executing shell commands</title>
		<link>http://webexpose.org/2007/03/06/executing-shell-commands/</link>
		<comments>http://webexpose.org/2007/03/06/executing-shell-commands/#comments</comments>
		<pubDate>Tue, 06 Mar 2007 09:54:59 +0000</pubDate>
		<dc:creator>michael</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://webexpose.org/2007/03/06/executing-shell-commands/</guid>
		<description><![CDATA[Just a quick post - if you&#8217;re using PHP&#8217;s shell_exec to execute shell commands, take note of the following:
Permissions
If you&#8217;re reading or writing files, ensure that your working directory has the correct permissions for the www/apache user to access what it needs. On some systems, PHP will run as the nobody user, so adjust accordingly.
Pipes
Using [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick post - if you&#8217;re using PHP&#8217;s <code><a href='http://www.php.net/shell_exec' title='shell_exec'>shell_exec</a></code> to execute shell commands, take note of the following:</p>
<p><strong>Permissions</strong><br />
If you&#8217;re reading or writing files, ensure that your working directory has the correct permissions for the www/apache user to access what it needs. On some systems, PHP will run as the nobody user, so adjust accordingly.</p>
<p><strong>Pipes</strong><br />
Using pipes and redirection inside your command string is not going to work most of the time, what you probably want to do is create a seperate bash script on your server that contains all the commands you want to run. Then use PHP to execute the single bash script.</p>
<p><strong>Paths</strong><br />
This one has got me a few times - just because a command is in the path when you&#8217;re SSH&#8217;d into the server, it doesn&#8217;t mean that it&#8217;ll be on PHP&#8217;s perceived path. This means that you&#8217;ll need to specify the full path to any system applications you are using (not for standard commands like <code>cat</code>, though). For example:</p>
<pre><code>   shell_exec("/usr/local/bin/htmldoc --jpeg=0 --webpage \
      -f out.pdf in.html");</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://webexpose.org/2007/03/06/executing-shell-commands/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Sorting arrays by an arbitary key value in PHP</title>
		<link>http://webexpose.org/2007/02/27/sorting-arrays-by-an-arbitary-key-value-in-php/</link>
		<comments>http://webexpose.org/2007/02/27/sorting-arrays-by-an-arbitary-key-value-in-php/#comments</comments>
		<pubDate>Tue, 27 Feb 2007 11:22:33 +0000</pubDate>
		<dc:creator>michael</dc:creator>
		
		<category><![CDATA[PHP]]></category>

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

		<guid isPermaLink="false">http://webexpose.org/2007/02/27/sorting-arrays-by-an-arbitary-key-value-in-php/</guid>
		<description><![CDATA[I often (a couple times a month) have to sort an array of arrays by some arbitrary value located in the internal array. For example, I might want to sort the following structure by name.
   Array[0] {
      Array[0] {
         id [...]]]></description>
			<content:encoded><![CDATA[<p>I often (a couple times a month) have to sort an array of arrays by some arbitrary value located in the internal array. For example, I might want to sort the following structure by name.</p>
<pre><code>   Array[0] {
      Array[0] {
         id => 1
         name => mike
         age => 20
      }

      Array[1] {
         id => 2
         name => bob
         age: 21
      }
   }</code></pre>
<p>I want the same structure returned, but the array containing &#8216;bob&#8217; in it&#8217;s name key must appear first in the array. PHP&#8217;s <code>sort()</code> function is insuffficient in this case, it sorts by the first key of each internal array (i.e. &#8216;id&#8217; in this case).</p>
<p>The solution is to use <code>usort()</code>, which allows for a custom compare function to be used.</p>
<pre><code>   function cmp($x, $y) {
      if ($x[1] == $y[1]) {
         return 0;
      } //if

      return ($x[1] > $y[1]) ? 1 : -1;
      //or return strcmp($x[1], $y[1]);
   } //cmp

   usort($array, 'cmp');</code></pre>
<p><code>usort()</code> takes the provided function name and uses it as the compare function between two elements. This also allows you to sort by multiple fields, if the first two fields are equal you can drop down to checking another field, and so on.</p>
]]></content:encoded>
			<wfw:commentRss>http://webexpose.org/2007/02/27/sorting-arrays-by-an-arbitary-key-value-in-php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Useful things to know in CakePHP</title>
		<link>http://webexpose.org/2007/02/14/useful-things-to-know-in-cakephp/</link>
		<comments>http://webexpose.org/2007/02/14/useful-things-to-know-in-cakephp/#comments</comments>
		<pubDate>Wed, 14 Feb 2007 13:43:53 +0000</pubDate>
		<dc:creator>michael</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://webexpose.org/2007/02/14/useful-things-to-know-in-cakephp/</guid>
		<description><![CDATA[CakePHP is an awesome MVC (Model-View-Controller) framework for PHP 4 and 5 - it provides a great base to build your web application on, and can save you a huge amount of time if used correctly.
Unfortunately, the manual is sometimes lacking - whilst the information you need might be there, you probably will not be [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://cakephp.org/' title='CakePHP'>CakePHP</a> is an awesome <a href='http://en.wikipedia.org/wiki/Model-view-controller' title='MVC'>MVC</a> (Model-View-Controller) framework for PHP 4 and 5 - it provides a great base to build your web application on, and can save you a huge amount of time if used correctly.</p>
<p>Unfortunately, the manual is sometimes lacking - whilst the information you need might be there, you probably will not be able to find it because it&#8217;s hidden away in some random corner. I&#8217;m going to cover a few common questions (in my opinion) here.</p>
<p><strong>How do I turn off the automatic database connection?</strong></p>
<p>Sometimes you want a controller and model that don&#8217;t have any mapping to the database - for example, a static page controller. Cake complains unless you have a correctly named table in the database when you view the page.</p>
<p>Add this line to your <strong>model</strong> file to disable this feature:</p>
<pre><code>   var $useTable = false;</code></pre>
<p><strong>How do I turn off auto-layout rendering?</strong></p>
<p>Cake also automatically lays out your controller methods into the default layout - you might want to turn this off if the controller deals with AJAX calls and returns simple responses, or simply if you want to make use of <code>print</code> and <code>print_r</code>.</p>
<p>At the top of your <strong>controller</strong>, inside the class, add:</p>
<pre><code>   var $autoRender = false;</code></pre>
<p>You can also disable this per method, as far as I know.</p>
<p>Additionally, Cake comes with a AJAX layout in the core that returns the template file without the default layout. You can use it by specifying the <code>render</code> function in the last line of your method (e.g. for <code>function myAction()</code>):</p>
<pre><code>   $this->render('myAction', 'ajax');</code></pre>
<p><strong>Where do I put application-wide code?</strong></p>
<p>Create a file called <strong><code>app_controller.php</code></strong> in your <code>app</code> directory:</p>
<p><strong>project/app/app_controller.php</strong></p>
<pre><code>   &lt;?php
      class AppController extends Controller {
         //code
      } //AppController
   ?&gt;</code></pre>
<p>This file overrides the default app controller that each of your controller&#8217;s extends, thus you can add any code here that you want all of your controllers to see.</p>
]]></content:encoded>
			<wfw:commentRss>http://webexpose.org/2007/02/14/useful-things-to-know-in-cakephp/feed/</wfw:commentRss>
		</item>
		<item>
		<title>B2B: Ajax in JQuery with special effects</title>
		<link>http://webexpose.org/2007/01/31/b2b-ajax-in-jquery-with-special-effects/</link>
		<comments>http://webexpose.org/2007/01/31/b2b-ajax-in-jquery-with-special-effects/#comments</comments>
		<pubDate>Tue, 30 Jan 2007 22:48:13 +0000</pubDate>
		<dc:creator>michael</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

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

		<guid isPermaLink="false">http://webexpose.org/2007/01/31/b2b-ajax-in-jquery-with-special-effects/</guid>
		<description><![CDATA[Today&#8217;s article is going to cover using the excellent JQuery library to implement an AJAX username availability checker (along with a bit of eye candy to show the results). The use of visual effects with AJAX can occasionally be quite tricky, depending on what you need to do - fades by definition will take a [...]]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s article is going to cover using the excellent <a href='http://jquery.com/' title='JQuery'>JQuery</a> library to implement an AJAX username availability checker (along with a bit of eye candy to show the results). The use of visual effects with AJAX can occasionally be quite tricky, depending on what you need to do - fades by definition will take a certain period of time to execute, so you need to stagger your calls correctly to get your data fading out and back in again at the correct time (after the AJAX calls have fired).</p>
<p>Like the previous JQuery introduction - <a href='http://webexpose.org/2006/12/28/jquery-pop-up-menu-tutorial/' title='JQuery Pop-up Menu'> JQuery Pop-up Menu Tutorial</a> - we&#8217;ll be using the latest JQuery library, and a seperate external javascript file to contain our behaviours and logic.</p>
<p>I&#8217;m going to skip the HTML in the hopes that you&#8217;ll actually whip up a test page yourself, and start playing around with JQuery - but obviously you need a quick description of the elements we&#8217;ll be using:</p>
<ul>
<li><strong>span</strong> with ID <code>usernameLoading</code>, containing an AJAX <a href='http://www.napyfab.com/ajax-indicators/' title='AJAX activity indicators'>spinner</a>.</li>
<li><strong>a</strong> with ID <code>usernameCheck</code> and href of <code>javascript:void(0)</code></li>
<li><strong>span</strong> with ID <code>usernameResult</code></li>
</ul>
<p>Onto the javascript:</p>
<p><strong>behaviour.js</strong></p>
<p><code>
<pre> 1  $(document).ready(function() {
 2    //username availability checker
 3    $('#usernameLoading').hide();
 4
 5    $('#usernameLoading').ajaxStart(function() {
 6      $(this).show();
 7    }).ajaxStop(function() {
 8      $(this).hide();
 9    });
10
11    $('#usernameCheck').click(function() {
12      $.post("/users/check", {
13        username: $('#UserUsername').val()
14      }, function(response){
15        $('#usernameResult').fadeOut();
16        setTimeout("finishAjax('usernameResult', '"+escape(response)+"')", 400);
17      });
18    });
19
20  });</code></pre>
<p>Yep, the bulk of the action occurs in less than 20 lines of javascript (not including one function that we&#8217;ll get to now).</p>
<p>Starting with our standard JQuery attach function, we immediately hide the <code>usernameLoading</code> DIV, as this is the DIV that contains our AJAX spinner image. Lines <strong>5</strong> to <strong>9</strong> simply say that whenever an AJAX event starts and stops, the respective code should be run. This obviously only works if there is one AJAX widget on a page, so you&#8217;ll have to be clever otherwise.</p>
<p>Line <strong>11</strong> says that when our <code>usernameCheck</code> <strong>a</strong> element is clicked, we fire off a <code>$.post</code> JQuery AJAX event, to the <code>/users/check</code> URL, with the correct username value from the input element.</p>
<p>You can view other <a href='http://jquery.com/docs/AJAXModule/' title='JQuery AJAX examples'>AJAX methods</a> and examples on the library homepage.</p>
<p>Line <strong>14</strong> says that once the call has finished, pass the response through to the anonymous function which fades out the current <code>usernameResult</code> DIV and then calls a <code>setTimeout</code> on another method called <code>finishAjax</code>. </p>
<p>Line <strong>16</strong> could be replaced by the following two lines:</p>
<p><code>
<pre>  $('#usernameResult').html(response);
  $('#usernameResult').fadeIn();</pre>
<p></code></p>
<p>If you try the above, you&#8217;ll find that the sparkly fading in and out effect is somewhat ruined by random flickering and nonsense (at least in my Firefox) - to get around this, I use <a href='http://www.w3schools.com/htmldom/met_win_settimeout.asp' title='setTimeout function'>setTimeout</a>.</p>
<p><code>
<pre> 1  function finishAjax(id, response) {
 2    $('#'+id).html(unescape(response));
 3    $('#'+id).fadeIn();
 4  } //finishAjax</pre>
<p></code></p>
<p>Be careful in passing your response text through; as you can see in line <strong>16</strong> of the initial listing, I escape the text and then unescape it in the <code>finishAjax</code> function. By waiting 400 milliseconds before replacing the inner HTML of the DIV and then fading it back in, we avoid the horrible flickering and such of the special effect.</p>
<p>The rest of the magic occurs at the <code>/users/check</code> URL - the username parameter is passed through and accessed in PHP&#8217;s <code>$_POST</code> array. It is then checked against the database, and depending on whether the username already exists or not, two different sets of HTML are passed back to the javascript AJAX handler.</p>
<p>In PHP, it&#8217;s as simple as this:</p>
<p><strong>check.php</strong><br />
<code>
<pre>  if ($userWasInDatabase) {
    print '&lt;strong&gt;Username is taken already!&lt;/strong&gt;';
  } else {
    print '&lt;strong&gt;Username available.&lt;/strong&gt;';
  } //else</pre>
<p></code></p>
<p>I think this turned out to be more of a HOWTO than a tutorial, but I think I&#8217;ll blame JQuery for that, everything just seems to happen without you having to even try hard. I also realise that I&#8217;ve skipped a lot of explanations, but I think you really need to pick up the library and play with it yourself to see how easy it is.</p>
]]></content:encoded>
			<wfw:commentRss>http://webexpose.org/2007/01/31/b2b-ajax-in-jquery-with-special-effects/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
