<?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>Stephen Gray&#039;s dev blog &#187; Tutorials</title>
	<atom:link href="http://blog.s-gray.com/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.s-gray.com</link>
	<description>e-commerce and integrations</description>
	<lastBuildDate>Sun, 17 Jan 2010 09:32:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Amazon S3 backup with PHP</title>
		<link>http://blog.s-gray.com/2010/01/14/amazon-s3-backup-with-php/</link>
		<comments>http://blog.s-gray.com/2010/01/14/amazon-s3-backup-with-php/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 10:22:05 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[s3]]></category>

		<guid isPermaLink="false">http://blog.s-gray.com/?p=207</guid>
		<description><![CDATA[I&#8217;ve just released the first version of s3Cinch, a script I wrote in PHP for archiving and backing up any file, folder or MySQL database to an Amazon Simple Storage Service (S3) account.
It&#8217;s pretty easy to use and the requirements are basic. It&#8217;s hosted on Google Code so feel free to play around with it. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just released the first version of s3Cinch, a script I wrote in PHP for archiving and backing up any file, folder or MySQL database to an Amazon Simple Storage Service (S3) account.</p>
<p>It&#8217;s pretty easy to use and the requirements are basic. It&#8217;s hosted on Google Code so feel free to play around with it. More details and usage instructions etc can be found on it&#8217;s project page and Wiki.</p>
<p><a href="http://code.google.com/p/s3cinch">s3Cinch on Google Code</a></p>
<p>There are a number of big features that I&#8217;ll be looking at implementing over the coming weeks so the script should be improving quite regularly.</p>
<p>Stephen.</p>
<p><strong>Update: version 1.1</strong></p>
<p>Added the ability to back up MySQL databases from remote servers.</p>
<p><strong>Update: version 1.2</strong></p>
<p>Added ability to control when backups are scheduled, either hourly, daily, weekly or monthly.<br />
Added commenting to instruction files.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2010/01/14/amazon-s3-backup-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento create a custom payment method</title>
		<link>http://blog.s-gray.com/2009/11/11/magento-create-a-custom-payment-method/</link>
		<comments>http://blog.s-gray.com/2009/11/11/magento-create-a-custom-payment-method/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 09:42:18 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[gateway]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[payment]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=136</guid>
		<description><![CDATA[I've been doing some work with the Magento e-commerce platform lately and my task was to create a new payment method to use during the standard checkout process.

After much searching online, it seems that any available tutorials for custom payment methods either don't work, are incomplete or worked in previous versions but are now updated. I developed this using version 1.3.2.2 of Magento.

I'm writing this tutorial with the intention of it being the definitive guide to creating a custom payment method.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been doing some work with the Magento e-commerce platform lately and my task was to create a new payment method to use during the standard checkout process.</p>
<p>I&#8217;ve come to the conclusion that Magento is very annoying to develop for if you know nothing about the platform. Yes the platform is open source but they also have a commercial version, therefore it seems they have tried to make it hard for you to know the complete ins and outs of the system. I.E. if something seems like too much of a task to develop, a company would likely purchase the commercial version and get it developed by the platform developers rather than do it themselves.</p>
<p>You also have to remember that Magento is built on top of the Zend framework, so when you are developing for it documentation does not all reside on the Magento site, you will have to look into how the Zend framework works as well.</p>
<p>Finally, note that by default the Magento checkout process uses AJAX to submit the form, making this a very annoying module to debug. Thankfully Magento makes it easy to log values and throw exceptions which &#8216;pause&#8217; the checkout process.</p>
<p>After much searching online, it seems that any available tutorials for custom payment methods either don&#8217;t work, are incomplete or worked in previous versions but are now updated. I developed this using version 1.3.2.2 of Magento.</p>
<p>I&#8217;m writing this tutorial with the intention of it being the definitive guide to creating a custom payment method.</p>
<p><strong><a href="#0">Prerequisites</a></strong><br />
<strong><a href="#1">1. Creating the module</a></strong><br />
<strong><a href="#2">2. Configuration through the admin</a></strong><br />
<strong><a href="#4">4. Payment adapter model class</a></strong></p>
<h2><a name="0"> Prerequisites</a></h2>
<p>There are a few things you need to note now to avoid confusion later down the line.</p>
<p>For your module, you need the main name and a simpler alias for it. I.E. if your module was called MyPaymentMethod, your alias could be mypayment. Keep the full name and the alias in mind. The full name will be used in class and folder names but the alias will be used when referencing the module anywhere else.</p>
<p>For this tutorial I will be using ModuleName for the full name, modulename for the module alias, and MyModules as the module namespace.</p>
<p>Magento names it&#8217;s classes after their path. I.E. you are going to have a class which handles all of this payment method logic, and it&#8217;s path will be something like app/code/local/MyModules/ModuleName/Model/PaymentLogic.php. It&#8217;s class name will be MyModules_ModuleName_Model_PaymentLogic. Remember this as it helps when trying to figure out where to find a referenced class etc.</p>
<h2><a name="1">Creating the module</a></h2>
<p>OK so first we need to create the initial module and make sure Magento knows that it exists. Lets create the folder structure;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p136code1'); return false;">View Code</a> TEXT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1361"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p136code1"><pre class="text" style="font-family:monospace;">app/
---- code/
-------- local/
------------ #1 MyModules
---------------- #2 ModuleName
-------------------- #3 Block
-------------------- #4 etc
-------------------- #5 Model</pre></td></tr></table></div>

<p><strong>#1</strong> In Magento terms, MyModules would be the module&#8217;s namespace. I.E. you&#8217;ll likely have one namespace for multiple modules. The namespace can be called anything but should be UpperCamelCase. If you take a look in app/code/core you will see a folder called Mage &#8211; this is the namespace for most of Magento&#8217;s core modules.</p>
<p><strong>#2</strong> This is your actual module name. This should be UpperCamelCase.</p>
<p><strong>#3</strong> This folder is used to contain block classes that are used in your module.</p>
<p><strong>#4</strong> This is where your module configuration will go.</p>
<p><strong>#5</strong> The class that handles all of your payment gateway logic will go here. This is also a good place to put any third party libraries or custom classes you may use.</p>
<p><strong>config.xml</strong></p>
<p>Create the file config.xml in app/code/local/MyModules/ModuleName/config. This file is the main module configuration file. For now, you want it to look like this;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p136code2'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1362"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
</pre></td><td class="code" id="p136code2"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">        register the full module name and it's</span>
<span style="color: #808080; font-style: italic;">        version</span>
<span style="color: #808080; font-style: italic;">    --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;MyModules_ModuleName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0.1.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/MyModules_ModuleName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">        global module configuration</span>
<span style="color: #808080; font-style: italic;">    --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">            register the module's model group</span>
<span style="color: #808080; font-style: italic;">            note that we use the module's alias</span>
<span style="color: #808080; font-style: italic;">            mentioned in the prerequisites</span>
<span style="color: #808080; font-style: italic;">        --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;models<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modulename<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>MyModules_ModuleName_Model<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modulename<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/models<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">            set which resources the module will</span>
<span style="color: #808080; font-style: italic;">            use when setting up, writing to the db</span>
<span style="color: #808080; font-style: italic;">            and reading from the db. we're going</span>
<span style="color: #808080; font-style: italic;">            to use the core connections.</span>
<span style="color: #808080; font-style: italic;">        --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modulename_setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>MyModules_ModuleName<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>core_setup<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modulename_setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modulename_write<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>core_write<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modulename_write<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modulename_read<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>core_read<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modulename_read<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Now the module has it&#8217;s basic configuration but Magento doesn&#8217;t care because the module is not yet registered.</p>
<p><strong>MyModules_All.xml</strong></p>
<p>Create the file MyModules_All.xml in app/etc/modules. This is where we register the module. You want this file to look like this;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p136code3'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1363"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code" id="p136code3"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;MyModules_ModuleName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;active<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/active<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
            <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                for now we're telling the system that</span>
<span style="color: #808080; font-style: italic;">                this module is just local, it's not a core</span>
<span style="color: #808080; font-style: italic;">                or community module and resides in</span>
<span style="color: #808080; font-style: italic;">                app/code/local.</span>
<span style="color: #808080; font-style: italic;">            --&gt;</span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;codePool<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>local<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/codePool<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/MyModules_ModuleName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The module is now registered and Magento knows about it. But what can you do with it? Well, this is a payment method module, so we need to register it as a usable payment method. We also need to be able to set what fields are configured in the administration section that can be used when authenticating with the payment gateway etc.</p>
<h2><a name="2">Configuration through the admin</a></h2>
<p><strong>system.xml</strong></p>
<p>Create the file system.xml in app/code/local/MyModules/ModuleName/etc. Here we will tell Magento to have a new section in the payment methods configuration area for configuring this module. We also set what fields we want there. For every field, we have an element like this;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p136code4'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1364"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p136code4"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;field_name</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Field name<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>field type<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>field source model class<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/field_name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>As you will see below. To start with, have the file looking like this;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p136code5'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1365"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
</pre></td><td class="code" id="p136code5"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sections<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">            here we're telling the system we</span>
<span style="color: #808080; font-style: italic;">            we want to add a new config section</span>
<span style="color: #808080; font-style: italic;">            in the payment method area</span>
<span style="color: #808080; font-style: italic;">        --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;payment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groups<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modulename</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span> <span style="color: #000066;">module</span>=<span style="color: #ff0000;">&quot;paygate&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
                    <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                        human readable module name</span>
<span style="color: #808080; font-style: italic;">                        which appears as the name of the</span>
<span style="color: #808080; font-style: italic;">                        payment method in the admin section</span>
<span style="color: #808080; font-style: italic;">                    --&gt;</span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>My Payment Module<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                    <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                        set where this method should appear</span>
<span style="color: #808080; font-style: italic;">                        in comparison to the other methods</span>
<span style="color: #808080; font-style: italic;">                        within the admin</span>
<span style="color: #808080; font-style: italic;">                    --&gt;</span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>670<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fields<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                        <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                            you need this field if you want the user to</span>
<span style="color: #808080; font-style: italic;">                            be able to disable/enable this payment</span>
<span style="color: #808080; font-style: italic;">                            method. leave this out if you don't want</span>
<span style="color: #808080; font-style: italic;">                            this to be optional</span>
<span style="color: #808080; font-style: italic;">                        --&gt;</span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;active</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Enabled<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>select<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                            <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                                we want to use the standard Magento</span>
<span style="color: #808080; font-style: italic;">                                yes/no select options</span>
<span style="color: #808080; font-style: italic;">                            --&gt;</span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>adminhtml/system_config_source_yesno<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/active<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                        <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                            the below two fields are an example</span>
<span style="color: #808080; font-style: italic;">                            of fields you may need if integrating with</span>
<span style="color: #808080; font-style: italic;">                            a payment gateway's API. you will see how</span>
<span style="color: #808080; font-style: italic;">                            to retrieve these values in your code later</span>
<span style="color: #808080; font-style: italic;">                        --&gt;</span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;api_key</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>API Key<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>text<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/api_key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;api_secret</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>API Secret<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>text<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>3<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/api_secret<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                        <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                            having this field here allows the user</span>
<span style="color: #808080; font-style: italic;">                            to set whether we want payments to be</span>
<span style="color: #808080; font-style: italic;">                            authorised or authorised AND captured</span>
<span style="color: #808080; font-style: italic;">                            if you don't want the user to choose you</span>
<span style="color: #808080; font-style: italic;">                            can leave this field out</span>
<span style="color: #808080; font-style: italic;">                        --&gt;</span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;payment_action</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Payment Action<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>select<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                            <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                                we're using the source from the paygate</span>
<span style="color: #808080; font-style: italic;">                                module as it has the options we want. this</span>
<span style="color: #808080; font-style: italic;">                                is safe because the paygate module is a core</span>
<span style="color: #808080; font-style: italic;">                                Magento module and therefore will be there</span>
<span style="color: #808080; font-style: italic;">                                with any default install. if it makes you feel</span>
<span style="color: #808080; font-style: italic;">                                safer you can create your own field source model</span>
<span style="color: #808080; font-style: italic;">                                but that isn't covered in this tutorial</span>
<span style="color: #808080; font-style: italic;">                            --&gt;</span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>paygate/authorizenet_source_paymentAction<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>4<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/payment_action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                        <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                            what do you want the status to be of</span>
<span style="color: #808080; font-style: italic;">                            new orders made using this payment</span>
<span style="color: #808080; font-style: italic;">                            method?</span>
<span style="color: #808080; font-style: italic;">                        --&gt;</span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;order_status</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>New order status<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>select<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>adminhtml/system_config_source_order_status_processing<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>5<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/order_status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                        <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                            this field lets the user choose the</span>
<span style="color: #808080; font-style: italic;">                            name of the payment method as it</span>
<span style="color: #808080; font-style: italic;">                            appears to the normal user on your site</span>
<span style="color: #808080; font-style: italic;">                        -&gt;</span>
<span style="color: #808080; font-style: italic;">                        &lt;title translate=&quot;label&quot;&gt;</span>
<span style="color: #808080; font-style: italic;">                            &lt;label&gt;Title&lt;/label&gt;</span>
<span style="color: #808080; font-style: italic;">                            &lt;frontend_type&gt;text&lt;/frontend_type&gt;</span>
<span style="color: #808080; font-style: italic;">                            &lt;sort_order&gt;6&lt;/sort_order&gt;</span>
<span style="color: #808080; font-style: italic;">                            &lt;show_in_default&gt;1&lt;/show_in_default&gt;</span>
<span style="color: #808080; font-style: italic;">                            &lt;show_in_website&gt;1&lt;/show_in_website&gt;</span>
<span style="color: #808080; font-style: italic;">                            &lt;show_in_store&gt;0&lt;/show_in_store&gt;</span>
<span style="color: #808080; font-style: italic;">                        &lt;/title&gt;</span>
<span style="color: #808080; font-style: italic;">                    &lt;/fields&gt;</span>
<span style="color: #808080; font-style: italic;">                &lt;/modulename&gt;</span>
<span style="color: #808080; font-style: italic;">            &lt;/groups&gt;</span>
<span style="color: #808080; font-style: italic;">        &lt;/payment&gt;</span>
<span style="color: #808080; font-style: italic;">    &lt;/sections&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;/config&gt;</span></pre></td></tr></table></div>

<p><strong>Default configuration values</strong></p>
<p>Before we go and test this, we should set some default values for the configuration fields we just created.</p>
<p>Open app/code/local/MyModules/ModuleName/etc/config.xml and add the following section;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p136code6'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1366"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
</pre></td><td class="code" id="p136code6"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    ...
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;payment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modulename<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                    is this payment method enabled?</span>
<span style="color: #808080; font-style: italic;">                --&gt;</span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;active<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/active<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                    this is where we tell the system what</span>
<span style="color: #808080; font-style: italic;">                    class to use to handle all of the payment</span>
<span style="color: #808080; font-style: italic;">                    logic. we call this class the payment</span>
<span style="color: #808080; font-style: italic;">                    adapter model class. you can change the</span>
<span style="color: #808080; font-style: italic;">                    paymentLogic bit to be what you want</span>
<span style="color: #808080; font-style: italic;">                    but it has to be lowerCamelCase and</span>
<span style="color: #808080; font-style: italic;">                    the class name will have to be changed later</span>
<span style="color: #808080; font-style: italic;">                    on as you will see</span>
<span style="color: #808080; font-style: italic;">                --&gt;</span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>modulename/paymentLogic<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;order_status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>pending<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/order_status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Credit Card (My Payment Method)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;api_key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1234<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/api_key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;api_secret<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1234<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/api_secret<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                    this is the default set of allowed credit</span>
<span style="color: #808080; font-style: italic;">                    card types. leave this as it is for now</span>
<span style="color: #808080; font-style: italic;">                --&gt;</span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cctypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>AE,VI,MC,DI,SS<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cctypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                    this should be authorize or authorize_capture</span>
<span style="color: #808080; font-style: italic;">                    you can probably guess that authorize just</span>
<span style="color: #808080; font-style: italic;">                    authorizes the payment but authorize_capture</span>
<span style="color: #808080; font-style: italic;">                    processes it as well</span>
<span style="color: #808080; font-style: italic;">                --&gt;</span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;payment_action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>authorize_capture<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/payment_action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                    this field is used to say whether you only</span>
<span style="color: #808080; font-style: italic;">                    want this method to be used for certain</span>
<span style="color: #808080; font-style: italic;">                    countries but that is not covered by this</span>
<span style="color: #808080; font-style: italic;">                    tutorial</span>
<span style="color: #808080; font-style: italic;">                --&gt;</span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allowspecific<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/allowspecific<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modulename<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/payment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Of course, if you have any of the fields in the above file configurable as set in system.xml, the user set value will be used.</p>
<p><strong>Test progress so far</strong></p>
<p>OK so now if you log into the Magento administration and go to System -&gt; Configuration -&gt; Payment methods you should see your new payment method somewhere in that list.</p>
<p>If you enable it it should then also be available if you checkout on your site as normal. Don&#8217;t complete any orders using it yet as there will be problems because we haven&#8217;t finished! We still need to create the most important part, the class which will handle all of the logic.</p>
<p>If you don&#8217;t see your payment method, please make sure you have completed the above steps correctly. Check for any simple mistakes and try clearing the Magento cache as well. The basic rule is; if it doesn&#8217;t appear in the payment method list in the administration section, there&#8217;s a problem with system.xml. If it doesn&#8217;t appear as a usable payment method when checking out, there could be a problem with config.xml.</p>
<h2><a name="4">Payment adapter model class</a></h2>
<p>Create the file PaymentLogic.php in app/code/local/MyModules/ModuleName/Model/. This is where we will put all of our payment gateway logic. First, the contents of the file;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p136code7'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1367"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
</pre></td><td class="code" id="p136code7"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> CompanyName_NewModule_Model_PaymentLogic <span style="color: #000000; font-weight: bold;">extends</span> Mage_Payment_Model_Method_Cc
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * unique internal payment method identifier
     */</span>
    protected <span style="color: #000088;">$_code</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'newmodule'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * this should probably be true if you're using this
     * method to take payments
     */</span>
    protected <span style="color: #000088;">$_isGateway</span>               <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * can this method authorise?
     */</span>
    protected <span style="color: #000088;">$_canAuthorize</span>            <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * can this method capture funds?
     */</span>
    protected <span style="color: #000088;">$_canCapture</span>              <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * can we capture only partial amounts?
     */</span>
    protected <span style="color: #000088;">$_canCapturePartial</span>       <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * can this method refund?
     */</span>
    protected <span style="color: #000088;">$_canRefund</span>               <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * can this method void transactions?
     */</span>
    protected <span style="color: #000088;">$_canVoid</span>                 <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * can admins use this payment method?
     */</span>
    protected <span style="color: #000088;">$_canUseInternal</span>          <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * show this method on the checkout page
     */</span>
    protected <span style="color: #000088;">$_canUseCheckout</span>          <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * available for multi shipping checkouts?
     */</span>
    protected <span style="color: #000088;">$_canUseForMultishipping</span>  <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * can this method save cc info for later use?
     */</span>
    protected <span style="color: #000088;">$_canSaveCc</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * this method is called if we are just authorising
     * a transaction
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> authorize <span style="color: #009900;">&#40;</span>Varien_Object <span style="color: #000088;">$payment</span><span style="color: #339933;">,</span> <span style="color: #000088;">$amount</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * this method is called if we are authorising AND
     * capturing a transaction
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> capture <span style="color: #009900;">&#40;</span>Varien_Object <span style="color: #000088;">$payment</span><span style="color: #339933;">,</span> <span style="color: #000088;">$amount</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * called if refunding
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> refund <span style="color: #009900;">&#40;</span>Varien_Object <span style="color: #000088;">$payment</span><span style="color: #339933;">,</span> <span style="color: #000088;">$amount</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * called if voiding a payment
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> void <span style="color: #009900;">&#40;</span>Varien_Object <span style="color: #000088;">$payment</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>If the payment_action option of &#8216;Authorise&#8217; has been selected, then only the authorize() method will be called and no payment can be taken automatically. If however the payment_action &#8216;Authorise and Capture&#8217; was selected, then only the capture() method will be called and that method should probably authorise the payment before capturing the funds. A bit confusing and not explained anywhere but that&#8217;s how it works!</p>
<p>The Varien_Object $payment object holds all data to do with the transaction and also the order.</p>
<p>So that&#8217;s it! That&#8217;s the method I used to add a custom payment gateway to Magento. Please note: I don&#8217;t work with Magento anymore so if you have a complicated question which requires looking into Magento code, I probably won&#8217;t be able to answer it &#8211; but ask anyway just in case!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2009/11/11/magento-create-a-custom-payment-method/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>jQuery retrieving the data from an AJAX call into the global scope</title>
		<link>http://blog.s-gray.com/2009/07/27/jquery-retrieving-the-data-from-an-ajax-call-into-the-global-scope/</link>
		<comments>http://blog.s-gray.com/2009/07/27/jquery-retrieving-the-data-from-an-ajax-call-into-the-global-scope/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 09:06:16 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[scope]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=133</guid>
		<description><![CDATA[You make an AJAX call within a jQuery function and you want the call to be synchronous so that you can use the data from the call in the function scope. This tutorial will show you how.]]></description>
			<content:encoded><![CDATA[<p>Another quick one. Reading around it seems to be an issue. You make an AJAX call within a function and you want the call to be synchronous so that you can use the data from the call in the function scope.</p>
<p>AJAX calls are obviously asynchronous. jQuery has a &#8216;async: false&#8217; option in AJAX calls but it is ignored by most (maybe all?) browsers. Using this method you can force a synchronous request and retrieve that data.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p133code8'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1338"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p133code8"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> myFunction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> myVariable <span style="color: #339933;">=</span> $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span>
    <span style="color: #009900;">&#123;</span>
        url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'someScript.php'</span><span style="color: #339933;">,</span>
        async<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">responseText</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>myVariable<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>So .responseText retrieves the text value of the response from the AJAX call. And because we&#8217;re assigning to a variable we are forcing a synchronous request. You can now use that variable as you see fit.</p>
<p>This causes an issue when you are trying to retrieve a JSON object from an AJAX call into the function scope. The best way I&#8217;ve found so far is to retrieve the JSON as a string and use a jquery JSON plugin to convert it into an accessible object. Or you could just use the &#8216;eval&#8217; method.</p>
<p>Stephen.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2009/07/27/jquery-retrieving-the-data-from-an-ajax-call-into-the-global-scope/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Custom SQL in symfony 1.2.3</title>
		<link>http://blog.s-gray.com/2009/06/29/custom-sql-in-symfony-1-2-3/</link>
		<comments>http://blog.s-gray.com/2009/06/29/custom-sql-in-symfony-1-2-3/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 09:59:24 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=128</guid>
		<description><![CDATA[A small snippet for performing custom SQL queries using symfony 1.2.3. The method to do this has varied slightly with the different symfony releases.]]></description>
			<content:encoded><![CDATA[<p>Quick one. A small snippet for performing custom SQL queries using symfony 1.2.3. The method to do this has varied slightly with the different symfony releases. The method found on the symfony site almost has a good example, this is just adding a bit to it (looping);</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p128code9'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1289"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p128code9"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$conn</span> <span style="color: #339933;">=</span> Propel<span style="color: #339933;">::</span><span style="color: #004000;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'SELECT * FROM `my_table`;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$statement</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$conn</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$statement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rowObj</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$statement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span>PDO<span style="color: #339933;">::</span><span style="color: #004000;">FETCH_OBJ</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <a href="http://www.php.net/var_dump"><span style="color: #990000;">var_dump</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rowObj</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Stephen.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2009/06/29/custom-sql-in-symfony-1-2-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery wildcard selectors &#8211; update</title>
		<link>http://blog.s-gray.com/2009/04/24/jquery-wildcard-selectors-update/</link>
		<comments>http://blog.s-gray.com/2009/04/24/jquery-wildcard-selectors-update/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 09:16:58 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[selector]]></category>
		<category><![CDATA[wildcard]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=123</guid>
		<description><![CDATA[On my first post on this blog I posted a small snippet to use a small regex pattern in jQuery selectors. This doesn't work anymore, go here for a working method: <a href="http://ropox.net/archives/1081">http://ropox.net/archives/1081</a>]]></description>
			<content:encoded><![CDATA[<p>Hello all,</p>
<p>On my first post on this blog I posted a small snippet to use a small regex pattern in jQuery selectors.</p>
<p>You can find the post here: <a href="http://colourgray.wordpress.com/2008/08/05/jquery-wildcard-selectors/">http://colourgray.wordpress.com/2008/08/05/jquery-wildcard-selectors/</a></p>
<p>I was reading through some comments and posts on some incoming links and it seems it wasn&#8217;t working for anyone anymore. I just tested it myself and unfortunately it&#8217;s true (at least with with jQuery v1.3.1). However! All is not lost, there is another method which I&#8217;ve tested from one of the incoming links to that post which you can find here:</p>
<p><a href="http://ropox.net/archives/1081">http://ropox.net/archives/1081</a></p>
<p>Cheers ropox!</p>
<p>Stephen.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2009/04/24/jquery-wildcard-selectors-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symfony &quot;Database &quot;&quot; does not exist.&quot; error</title>
		<link>http://blog.s-gray.com/2009/03/02/symfony-database-does-not-exist-error/</link>
		<comments>http://blog.s-gray.com/2009/03/02/symfony-database-does-not-exist-error/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 11:20:34 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[schema]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=119</guid>
		<description><![CDATA[Fix for symfony's annoying "Database "" does not exist." error.]]></description>
			<content:encoded><![CDATA[<p>Hello,</p>
<p>It&#8217;s definitely been too long since I posted here! I will try and post more regularly over the coming months&#8230;</p>
<p>Firstly, we came across this issue after writing a number of plugins for a symfony project. Each of these plugins had their own schema.yml files and therefore we didn&#8217;t need our own custom schema.yml file at that time.</p>
<p>Because of this, our config/schema.yml file looked like this:</p>
<p><code>&nbsp;&nbsp;&nbsp;&nbsp;propel:</code></p>
<p>Pretty, right? When we ran symfony propel:build-sql (after the other usual build tasks) we got the error:</p>
<p><code>&nbsp;&nbsp;&nbsp;&nbsp;Database "" does not exist.</code></p>
<p>In symfony&#8217;s glorious vibrant red error container. It seems when your schema file looks like ours did above, symfony generates the sqldb.map file for that file without a database name, our data/sql/sqldb.map file looked similar to this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p119code10'); return false;">View Code</a> TEXT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p11910"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p119code10"><pre class="text" style="font-family:monospace;"># Sqlfile -&gt; Database map
...
lib.model.schema.sql=propel
plugins.pluginName.lib.model.schema.sql=propel
plugins.pluginName2.lib.model.schema.sql=propel
generated-schema.sql=propel
generated-pluginName-schema.sql=propel
generated-pluginName2-schema.sql=propel
...</pre></td></tr></table></div>

<p>The quick fix, especially if you don&#8217;t want to have to add a custom table in your schema just to get round this, is to simple add &#8216;propel&#8217; onto the end of the line that is missing it.</p>
<p>Hopefully there&#8217;s a proper fix that I so far haven&#8217;t been bothered to find&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2009/03/02/symfony-database-does-not-exist-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>symfony Unable to parse default value as date/time value: &#039;0000-00-00 00:00:00&#039;</title>
		<link>http://blog.s-gray.com/2008/09/26/symfony-unable-to-parse-default-value-as-datetime-value-0000-00-00-000000/</link>
		<comments>http://blog.s-gray.com/2008/09/26/symfony-unable-to-parse-default-value-as-datetime-value-0000-00-00-000000/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 13:53:19 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=114</guid>
		<description><![CDATA[Fix for symfony error "Unable to parse default value as date/time value: '0000-00-00 00:00:00'"]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just made a change to a symfony project&#8217;s schema.yml file and tried to rebuild the model and came across this error message:</p>
<p>Unable to parse default value as date/time value: &#8216;0000-00-00 00:00:00&#8242;</p>
<p>Which was stopping the build. After looking at various places, it seems this is a problem with Creole, (propel&#8217;s DBAL).</p>
<p>Before PHP v5.2.4, you could do a strtotime on a value of 000-00-00 00:00:00 and you would get a weird date, something in 1999. Not sure why :S Since the 5.2.4 update however this bug has been fixed and you will now get boolean false returned.</p>
<p>The symfony plugin sfGuard, which is widely used, uses 0000-00-00 00:00:00 as a default value in it&#8217;s schema for some fields and this will now cause problems. To fix this, edit sfGuard&#8217;s schema and change those default values to something like 1970-01-01 and that should do the trick.</p>
<p>Unfortunately Creole isn&#8217;t actively maintained anymore so it&#8217;s not likely to be updated soon to fix this.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2008/09/26/symfony-unable-to-parse-default-value-as-datetime-value-0000-00-00-000000/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery loading remote/external javascript files using getScript()</title>
		<link>http://blog.s-gray.com/2008/09/22/jquery-loading-external-javascript-files-using-getscript/</link>
		<comments>http://blog.s-gray.com/2008/09/22/jquery-loading-external-javascript-files-using-getscript/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 08:57:22 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[external]]></category>
		<category><![CDATA[getScript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[remote]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=109</guid>
		<description><![CDATA[I found out that jQuery has a nice little method for loading external scripts into the page at run time called getScript(). It basically gets the contents of the external file using an AJAX request and then eval()s the code at runtime, which seems like a perfect way of doing it. I reckon it's much better than appending new &#60;script&#62; tags to the &#60;head&#62; tag as well.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working over the weekend on a site and I got to the part of writing the client side MVC using jQuery (because I love the idea now!).</p>
<p>I found out that jQuery has a nice little method for loading external scripts into the page at run time called getScript(). It basically gets the contents of the external file using an AJAX request and then eval()s the code at runtime, which seems like a perfect way of doing it. I reckon it&#8217;s much better than appending new &lt;script&gt; tags to the &lt;head&gt; tag as well.</p>
<p>The only issue is that it can take some time to load an external file so you can&#8217;t always run functions from within that file straight away. Thankfully there is a workaround for this using another jQuery method. You basically set all AJAX request to be synchronous before you run getScript() and then set AJAX requests to be asynchronous again after the script is loaded. If you end up loading like 20 files at the beginning of a page load this could take a while but hopefully you won&#8217;t be doing that <img src='http://blog.s-gray.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p109code11'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p10911"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p109code11"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajaxSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>async<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$.<span style="color: #660066;">getScript</span><span style="color: #009900;">&#40;</span>MVCRoot<span style="color: #339933;">+</span>fileName<span style="color: #339933;">+</span><span style="color: #3366CC;">'.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$.<span style="color: #660066;">ajaxSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>async<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><a href="http://docs.jquery.com/Ajax/jQuery.getScript">And here&#8217;s some more info on this lovely little function <img src='http://blog.s-gray.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2008/09/22/jquery-loading-external-javascript-files-using-getscript/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Flex save changes from an AdvancedDataGrid using itemEditEnd</title>
		<link>http://blog.s-gray.com/2008/09/15/flex-save-changes-from-an-advanceddatagrid-using-itemeditend/</link>
		<comments>http://blog.s-gray.com/2008/09/15/flex-save-changes-from-an-advanceddatagrid-using-itemeditend/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 10:38:22 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[advanceddatagrid]]></category>
		<category><![CDATA[datagrid]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[itemEditEnd]]></category>
		<category><![CDATA[save]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=96</guid>
		<description><![CDATA[Quick tutorial on how to retrieve the value of an edited cell from an AdvancedDataGrid.]]></description>
			<content:encoded><![CDATA[<p>I just remembered that I had trouble finding out what I could access with this event handler function. Sure it was easy to find out when the event is dispatched, but how can I access the new field value edited by the user? How do I access the previous value?</p>
<p>So this is just a simple example showing you that. This also applies to the normal DataGrid and standard list controls.</p>
<p>The itemEditEnd event is dispatched (it&#8217;s in the name) when a user finishes editing a cell so this is pretty much the best time to save the user&#8217;s changes to that field/row.</p>
<p>Here&#8217;s our function:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p96code12'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p9612"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code" id="p96code12"><pre class="actionscript" style="font-family:monospace;">protected <span style="color: #000000; font-weight: bold;">function</span> saveChange<span style="color: #66cc66;">&#40;</span>event:AdvancedDataGridEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #808080; font-style: italic;">/**
     * use event.dataField to get the edited field name
     */</span>
    <span style="color: #000000; font-weight: bold;">var</span> field:<span style="color: #0066CC;">String</span> = event.<span style="color: #006600;">dataField</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/**
     * i'm using the following line to get the 'id' of the row being edited
     * because i passed an 'id' field through from my dataProvider.
     */</span>
    <span style="color: #000000; font-weight: bold;">var</span> selectedID:<span style="color: #0066CC;">String</span> = event.<span style="color: #006600;">currentTarget</span>.<span style="color: #006600;">selectedItem</span>.<span style="color: #006600;">id</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/**
     * use the itemEditorInstance to get the newly edited value but retrieve
     * the previous value from the existing grid data. i'm using the default
     * textinput itemRenderer so I can retrieve the new value using the 
     * itemEditInstance's 'text' property.
     */</span>
    <span style="color: #000000; font-weight: bold;">var</span> newValue:<span style="color: #0066CC;">String</span> = event.<span style="color: #006600;">currentTarget</span>.<span style="color: #006600;">itemEditorInstance</span>.<span style="color: #0066CC;">text</span>;
    <span style="color: #000000; font-weight: bold;">var</span> prevValue:<span style="color: #0066CC;">String</span> = ProductPersonalisationList.<span style="color: #006600;">selectedItem</span><span style="color: #66cc66;">&#91;</span>event.<span style="color: #006600;">dataField</span><span style="color: #66cc66;">&#93;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">// run a http service call or something to save the change or validate the data</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2008/09/15/flex-save-changes-from-an-advanceddatagrid-using-itemeditend/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>jQuery create a client-side MVC</title>
		<link>http://blog.s-gray.com/2008/08/28/jquery-create-a-client-side-mvc/</link>
		<comments>http://blog.s-gray.com/2008/08/28/jquery-create-a-client-side-mvc/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 16:59:15 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[mvc]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=85</guid>
		<description><![CDATA[Some concepts for creating a client side MVC (or VC in this case) framework.]]></description>
			<content:encoded><![CDATA[<p>A while ago a colleague suggested to me the idea of having a client-side MVC (Model View Controller) framework. At first I didn&#8217;t like the idea. I have always thought that all client-side code should be seen as one layer, one collection of files that all act as one set of functionality. Whether that be AJAX calls or general functions etc etc.</p>
<p>Then I began to think about it. We already know that a client-side MVC is possible, but I can now see why it would be useful. But it wouldn&#8217;t be the traditional MVC architecture, it would really only be VC, the view and controller layers. And that&#8217;s all it can ever really be. Javascript can never directly access the model in a web application environment.</p>
<p>I decided that a VC client-side system would still be useful and I&#8217;m probably going to develop one for future use. I haven&#8217;t got round to doing this yet but these are my ideas.</p>
<p>Firstly, looking at a few of our sites, I could quickly see that there were many javascript files being loaded per page as they were needed. The number of files could range from 5 to 10 or even more. So we need a way of dynamically loading javascript files onto the page as and when they are needed, on the fly. I initially thought that it wasn&#8217;t possible to dynamically load javascript files from within a javascript page but I Googled around a bit and when I found the solution it was painfully obvious: you simply load more  tags in the  section of the HTML.</p>
<p>So with that in mind, lets create a simple front controller. What does it need to do? It needs to have some basic configuration for the MVC; where the root of the files are etc. It needs to have the aforementioned function to load external javascript files into the current page. It needs to have an initialisation function which kicks the MVC off:</p>
<p>mvc.init.js</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p85code13'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p8513"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
</pre></td><td class="code" id="p85code13"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * client MVC initialiser
 */</span>
&nbsp;
<span style="color: #006600; font-style: italic;">/**
 * wheres are the MVC files?
 *
 * @access public
 * @var    string
 */</span>
<span style="color: #003366; font-weight: bold;">var</span> MVCRoot <span style="color: #339933;">=</span> <span style="color: #3366CC;">'/js/'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">/**
 * initialise the controller
 */</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    loadJS<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mvc.controller'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Controller.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">/**
 * load an external js file by appending
 * script tag as child to &amp;lt;head&amp;gt; section
 *
 * @var    fileName name of file to load
 * @return bool true on success, false on no fileName given
 */</span>
<span style="color: #003366; font-weight: bold;">function</span> loadJS<span style="color: #009900;">&#40;</span>fileName <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fileName <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&amp;lt;script type=&quot;text/javascript&quot; src=&quot;'</span><span style="color: #339933;">+</span>MVCRoot<span style="color: #339933;">+</span>fileName<span style="color: #339933;">+</span><span style="color: #3366CC;">'.js&quot;&amp;gt;&amp;lt;/script&amp;gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'head'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">else</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Ok most of that should make sense. The loadJS() function is fairly straight forward, it simply builds a HTML &lt;script&gt; tag for the new javascript file and appends it to the &lt;head&gt; tag of the HTML. The $(document).ready function then uses this function to &#8216;include&#8217; the main controller file (which will be /js/mvc.controller.js according to the current config). Now that the init function can call methods of the Controller class it calls the main controller&#8217;s initialisation method.</p>
<p>As an initial idea, the main controller could start off looking like this:</p>
<p>mvc.controller.js</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p85code14'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p8514"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</pre></td><td class="code" id="p85code14"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * client main controller
 */</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> Controller <span style="color: #339933;">=</span> 
<span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">/**
     * holds the current page's type
     * used for loading required js files etc
     *
     * @var    string
     * @access protected
     */</span>
    <span style="color: #003366; font-weight: bold;">var</span> _pageType <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">/**
     * main controller init function
     * gets current page type
     * includes required js files
     */</span>
    <span style="color: #003366; font-weight: bold;">var</span> init <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        loadJS<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mvc.controller.ajax'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Controller._getPageType<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">/**
         * logic to include required files dependent on page
         * type etc etc
         */</span>
        ...
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">/**
     * returns the page type for current URI
     *
     * @return void
     */</span>
    <span style="color: #003366; font-weight: bold;">var</span> _getPageType <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> currentURI <span style="color: #339933;">=</span> window.<span style="color: #660066;">location</span><span style="color: #339933;">;</span>
        Controller._pageType <span style="color: #339933;">=</span> ControllerAjax.<span style="color: #660066;">getPageType</span><span style="color: #009900;">&#40;</span>currentURI<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Again this is mostly basic stuff and it definitely hasn&#8217;t been tested but I think the general idea is in the right direction. I think now that I can visualise how to seperate out javascript objects more clearly I can see how this would benefit a javascript heavy web site/application.</p>
<p>Even though web frameworks have been gaining more and more popularity over recent years I hadn&#8217;t thought of applying the same methodical approach to client side coding until my colleague suggested this idea. I think if you think about it and you&#8217;re thinking like I was, you can quickly warm to the idea as I have. Almost every day you can read a new article about how in development, we need to be separating out our different types of logic and our layers. Javascript is of course just another language, so why should it not get the same treatment? <img src='http://blog.s-gray.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2008/08/28/jquery-create-a-client-side-mvc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>XML namespaces</title>
		<link>http://blog.s-gray.com/2008/08/26/xml-namespaces/</link>
		<comments>http://blog.s-gray.com/2008/08/26/xml-namespaces/#comments</comments>
		<pubDate>Tue, 26 Aug 2008 09:33:02 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[namespaces]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=81</guid>
		<description><![CDATA[If you&#8217;re a developer, I&#8217;m sure you would have seen XML namespaces somewhere before whilst looking at an XML document. But what are they? According to the Wiki page:
&#8220;XML namespaces are used for providing uniquely named elements and attributes in an XML instance. They are defined by a W3C recommendation called Namespaces in XML. An [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re a developer, I&#8217;m sure you would have seen XML namespaces somewhere before whilst looking at an XML document. But what are they? According to the <a href="http://en.wikipedia.org/wiki/XML_namespace">Wiki page</a>:</p>
<blockquote><p>&#8220;XML namespaces are used for providing uniquely named elements and attributes in an XML instance. They are defined by a W3C recommendation called Namespaces in XML. An XML instance may contain element or attribute names from more than one XML vocabulary. If each vocabulary is given a namespace then the ambiguity between identically named elements or attributes can be resolved.&#8221;</p></blockquote>
<p>So they provide a way of differentiating between similar, or same named XML elements/attributes in an XML document. How do you use them? Here&#8217;s an example:</p>
<p><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;</code><br />
<code>&lt;root xmlns:prod="http://www.my-site.com/namespaces/product" xmlns:ship="http://www.my-site.com/namespaces/shipping"&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&lt;prod:items&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;prod:item&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;prod:name value="My product" /&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;prod:code value="123321" /&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;prod:price prod:currency="GBP" value="11.99" /&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/prod:item&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/prod:items&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&lt;ship:method ship:postCode="CR3 4FT"&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ship:name value="Next day AM" /&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ship:price ship:currency="GBP" value="3.99" /&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/ship:method&gt;</code><br />
<code>&lt;/root&gt;</code></p>
<p>The first thing you&#8217;ll probably notice is the use of the xmlns attributes of the root node. This is used to declare a namespace. It can be used on any node and only child nodes of a node with the xmlns attribute will be able to use that namespace.</p>
<p>The part after the colon &#8211; in one of our cases &#8216;prod&#8217; &#8211; is the alias for the namespace. All elements and attributes of that namespace have to be prefixed with this alias. The URL that the xmlns attribute points to doesn&#8217;t actually have to contain anything, it doesn&#8217;t even really have to exist. Your standard browser XML parser doesn&#8217;t take any information from this URL, it&#8217;s just there for usability. Some people use this URL to give information on what the namespace in question is used for and what it&#8217;s attributes/elements are. Oh, and it can&#8217;t be an empty string (&#8221;")!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2008/08/26/xml-namespaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery create a simple plugin</title>
		<link>http://blog.s-gray.com/2008/08/11/jquery-create-a-simple-plugin/</link>
		<comments>http://blog.s-gray.com/2008/08/11/jquery-create-a-simple-plugin/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 11:33:32 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=72</guid>
		<description><![CDATA[This is just a quick tutorial (more of a code snippet) for creating a very simple plugin for jQuery.
Of course, there are lots of tutorials around for this, this is mainly for reference  
$.fn.myFunction = function()
{
    // use the following loop to iterate through all objects 
    // returned by the jQuery selector which was used
    return [...]]]></description>
			<content:encoded><![CDATA[<p>This is just a quick tutorial (more of a code snippet) for creating a very simple plugin for jQuery.</p>
<p>Of course, there are lots of tutorials around for this, this is mainly for reference <img src='http://blog.s-gray.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><code>$.fn.myFunction = function()</code><br />
<code>{</code><br />
<code>    // use the following loop to iterate through all objects </code><br />
<code>    // returned by the jQuery selector which was used</code><br />
<code>    return this.each(function()</code><br />
<code>    {</code><br />
<code>        // here we can access any properties using</code><br />
<code>        // the normal jQuery selectors</code><br />
<code>        alert($(this).html());</code><br />
<code>        $(this).addClass('red');</code><br />
<code>    });</code><br />
<code>};</code></p>
<p>So this function alerts the HTML of the selected element(s) and adds a new class &#8216;red&#8217;. You can then call the new function using:</p>
<p><code>$('#myElement').myFunction();</code></p>
<p>Another example of how easy and powerful jQuery is <img src='http://blog.s-gray.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  <a href="http://docs.jquery.com/Plugins/Authoring" target="_blank">Look here for more information</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2008/08/11/jquery-create-a-simple-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex getting selected RadioButton value</title>
		<link>http://blog.s-gray.com/2008/08/11/flex-getting-selected-radiobutton-value/</link>
		<comments>http://blog.s-gray.com/2008/08/11/flex-getting-selected-radiobutton-value/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 11:21:33 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[radio button]]></category>
		<category><![CDATA[radio button group]]></category>
		<category><![CDATA[selectedValue]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=65</guid>
		<description><![CDATA[This is a pretty simple one but there are surprisingly few tutorials showing the user simply how to get a selected RadioButtonGroup&#8217;s value.
There are quite a number of tutorials covering change event triggers for RadioButton controls but this is slightly different.
Say you have a form and you want to process the RadioButton value after submitting [...]]]></description>
			<content:encoded><![CDATA[<p>This is a pretty simple one but there are surprisingly few tutorials showing the user simply how to get a selected RadioButtonGroup&#8217;s value.</p>
<p>There are quite a number of tutorials covering change event triggers for RadioButton controls but this is slightly different.</p>
<p>Say you have a form and you want to process the RadioButton value after submitting the form instead of when the value of it changes.</p>
<p>To do this you actually have to create a RadioButtonGroup MXML tag for the radio buttons and select the value using the &#8217;selectedValue&#8217; property of that RadioButtonGroup:</p>
<p><code>&lt;mx:RadioButtonGroup id="myRadioButtonGroup" enabled="true" /&gt;</code><br />
<code>&lt;mx:RadioButton label="I like RadioButtons" groupName="{myRadioButtonGroup}" left="505" top="64" selected="true" value="true"/&gt;</code><br />
<code>&lt;mx:RadioButton label="I don't like RadioButtons" groupName="{myRadioButtonGroup}" left="348" top="62" value="false"/&gt;</code></p>
<p>Notice the {} around the groupName attributes of the RadioButton controls. You can then do this to select the value:</p>
<p><code>Alert.show(myRadioButtonGroup.selectedValue.toString());</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2008/08/11/flex-getting-selected-radiobutton-value/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Flex Processing XML response from HTTPService</title>
		<link>http://blog.s-gray.com/2008/08/08/flex-processing-xml-response-from-httpservice/</link>
		<comments>http://blog.s-gray.com/2008/08/08/flex-processing-xml-response-from-httpservice/#comments</comments>
		<pubDate>Fri, 08 Aug 2008 10:20:34 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[e4x]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[httpservice]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=17</guid>
		<description><![CDATA[There are a number of tutorials on doing this around the web but I thought I&#8217;d write my own tailored tutorial on this topic.
I&#8217;m going to cover two scenarios;
Assigning XML results as a dataProvider:
This is by far the simplest of the two:
// The initialisation function
protected function init():void
{
&#160;&#160;&#160;&#160;var serviceObj:HTTPService = new HTTPService();
&#160;&#160;&#160;&#160;serviceObj.resultFormat = 'e4x';
&#160;&#160;&#160;&#160;serviceObj.method = 'GET';
&#160;&#160;&#160;&#160;serviceObj.useProxy [...]]]></description>
			<content:encoded><![CDATA[<p>There are a number of tutorials on doing this around the web but I thought I&#8217;d write my own tailored tutorial on this topic.</p>
<p>I&#8217;m going to cover two scenarios;</p>
<p><strong>Assigning XML results as a dataProvider:</strong></p>
<p>This is by far the simplest of the two:</p>
<p><code>// The initialisation function</code><br />
<code>protected function init():void</code><br />
<code>{</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;var serviceObj:HTTPService = new HTTPService();</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;serviceObj.resultFormat = 'e4x';</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;serviceObj.method = 'GET';</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;serviceObj.useProxy = false;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;serviceObj.addEventListener(ResultEvent.RESULT, processResult);</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;serviceObj.url = 'myScriptURL.php';</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;serviceObj.send();</code><br />
<code>}</code></p>
<p><code>// The result processing function</code><br />
<code>protected function processResult(response:ResultEvent):void</code><br />
<code>{</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;// make sure the response is cast as the correct data type<br />
</code><code>&nbsp;&nbsp;&nbsp;&nbsp;var XMLResults:XML = response.result as XML;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;MyDataGrid.dataProvider = XMLResults.user;</code><br />
<code>}</code></p>
<p><code>// Sample XML sent from the server</code><br />
<code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;</code><br />
<code>&lt;users&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&lt;user&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;id&gt;1&lt;/id&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;username&gt;stephen&lt;/username&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;email&gt;stephen@example.com&lt;/email&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/user&gt;</code><br />
<code>&lt;/users&gt;</code></p>
<p>You&#8217;ll notice I&#8217;ve set the resultFormat attribute of the HTTPService object to be &#8216;e4x&#8217;. In my experience I&#8217;ve found e4x more useful to work with XML in Flex. e4x stands for ECMAScript for XML and <a href="http://en.wikipedia.org/wiki/E4X" target="_blank">you can find out more about it here</a>. e4x allows you to use XML as a primitive data type in your actionscript. I.E. you can do:</p>
<p><code>var myXML:XML = &lt;root&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;myNode&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;myChildNode /&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/myNode&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/root&gt;;</code></p>
<p>When using e4x as the result format, you don&#8217;t have to reference the root node when processing the XML, which is why I use the line</p>
<p><code>MyDataGrid.dataProvider = XMLResults.user;</code></p>
<p>instead of</p>
<p><code>MyDataGrid.dataProvider = XMLResults.users.user;</code></p>
<p><strong>Creating a new XML dataProvider from an existing RPC result</strong></p>
<p>This method is slightly more complicated but isn&#8217;t really needed as much. There&#8217;s really only a few situations that this would come in handy but I&#8217;ve had to use it on a recent project so I thought I may aswell post it.</p>
<p>Say you are making a call to a preexisting web service which is out of your control. In my situation, the web service WAS in my control, but it was already being used for other means so changing the output now wasn&#8217;t really an option. I wanted to process the XML, perform some logic on it and then add a new variable or two into the XML before assigning it to my DataGrid control.</p>
<p>The method I used in the end is quite simple and quick to do. You basically create a new empty XML document, loop through the results of the web service call, perform your logic and rebuild the new values into the new XML document. You then assign it to your control:</p>
<p><code>protected function processResult(response:ResultEvent):void</code><br />
<code>{</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;// make sure the response is cast as the correct data type</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;var XMLResults:XML = response.result as XML;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;// create the new XML document</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;var newXML:XML = new XML('&lt;users&gt;&lt;/users&gt;');</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;// loop through previous results</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;for (var i:String in XMLResults.users)</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;{</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// userXML is going to be our new user XML record</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var userXML:XML = new XML();</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// status is the new variable I want to add to the dataProvider</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var status:String;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// perform some logic on the previous results</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (XMLResults.users.activated[i] == 1)</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status = 'Active';</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status = 'Inactive';</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// build the new XML record for this user</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// we can use {XMLResults.user.field[i]} to keep any previous elements in tact that we want to keep</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// use the {} parenthesis to put actionscript variables into the XML datatype</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userXML = </code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;user&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{XMLResults.user.username[i]}</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{XMLResults.user.email[i]}</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;status&gt;{status}&lt;/status&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/user&gt;;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// add the new user record to the XML document</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newXML = newXML.appendChild(userXML);</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;}</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;MyDataGrid.dataProvider = newXML;</code><br />
<code>}</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2008/08/08/flex-processing-xml-response-from-httpservice/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MySQL basic reference</title>
		<link>http://blog.s-gray.com/2008/08/06/mysql-basic-reference/</link>
		<comments>http://blog.s-gray.com/2008/08/06/mysql-basic-reference/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 13:14:14 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[reference]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=33</guid>
		<description><![CDATA[A couple of colleagues have suggested putting a basic reference to some SQL commands together. Instead of having to reference different tutorials in different places around the web.
Of course there are a large number of tutorials around for this but again, this is just for reference.
Also, a lot of these commands will work for other [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of colleagues have suggested putting a basic reference to some SQL commands together. Instead of having to reference different tutorials in different places around the web.</p>
<p>Of course there are a large number of tutorials around for this but again, this is just for reference.</p>
<p>Also, a lot of these commands will work for other database engines which support SQL, but I mainly work with MySQL <img src='http://blog.s-gray.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I might possibly add a more advanced reference at a later date.</p>
<p><strong>Creating a table</strong></p>
<p><code>CREATE TABLE `table_name`<br />
(<br />
&nbsp;&nbsp;&nbsp;&nbsp;`id` INT(11) AUTO_INCREMENT NOT NULL,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`field_1` VARCHAR(50) NOT NULL,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`field_2` VARCHAR(255) NOT NULL,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`field_3` TEXT,<br />
&nbsp;&nbsp;&nbsp;&nbsp;PRIMARY KEY (`id`)<br />
)</code></p>
<p>So the lines for adding fields are in the format:</p>
<p>`field_name` FIELD_TYPE EXTRA_OPTIONS</p>
<p>You can get a list of all <a target="_blank" href="http://help.scibit.com/Mascon/masconMySQL_Field_Types.html">supported field types in MySQL here</a>.</p>
<p>Extra options that I&#8217;ve used here are;</p>
<p>AUTO_INCREMENT &#8211; This tells MySQL that this field is going to be this table&#8217;s auto incremented field. This means the field will go up by one for each new row. There can only be one auto incremented field per table. This is usually used for primary keys / row identification fields.</p>
<p>NOT NULL &#8211; This tells MySQL to not default to NULL values for these fields as there will always be a value inserted here.</p>
<p>I&#8217;ve also added a PRIMARY KEY instruction to this query. It&#8217;s good practice for every table to have a primary key, even if you see no obvious use for one. This is usually an id field as shown above. To have a field set as auto incremented, it must also be a primary key, otherwise MySQL will throw an error.</p>
<p><strong>Removing or emptying a table</strong></p>
<p><code>DROP TABLE `table_name`;</code></p>
<p><code>DELETE FROM `table_name`;</code></p>
<p><code>TRUNCATE TABLE `table_name`;</code></p>
<p>DROP TABLE will completely remove the table from the database. It will be as if this table never existed and it will have to be created to be used again. I&#8217;ve only really had to use DROP TABLE when I&#8217;ve made a mistake in creating the table and it&#8217;s easier to completely remove it and re-create it instead of amending it.</p>
<p>DELETE FROM `table` will do exactly that. It will delete all rows from the table but leave the table structure in tact. This is useful for a quick clean up of something like test entries but keep in mind that an auto incremented field will keep the last auto incremented value after this query. I.E. if you had 400 rows and you run a DELETE query as shown above, the next time you enter a row into this table, the auto incremented field value will be 401, not 1.</p>
<p>TRUNCATE TABLE does the same as DELETE FROM except that instead of deleting all records, it resets the table. I.E. all rows are removed and auto incremented field value is reset to 0.</p>
<p><strong>Amending a table</strong></p>
<p><code>ALTER TABLE `table_name` RENAME `new_table_name`;</code></p>
<p><code>ALTER TABLE `table_name` ADD `new_field` FIELD_TYPE OPTIONS [FIRST/AFTER `field_name`];</code></p>
<p><code>ALTER TABLE `table_name` CHANGE `field_name` `new_field_name` NEW_FIELD_TYPE NEW_OPTIONS;</code></p>
<p>The first query simple renames a table to a different table name.</p>
<p>The second query is used to add new fields to an existing table. The FIELD_TYPE and OPTIONS can be the same as noted above. You can use the FIRST/AFTER part to add the field to a particular place in the table, I.E.:</p>
<p><code>ALTER TABLE `table_name` ADD `field_name` VARCHAR(255) NOT NULL AFTER `id`;<br />
ALTER TABLE `table_name` ADD `another_field_name` VARCHAR(255) NOT NULL FIRST;</code></p>
<p>The third query can be used to alter an existing field&#8217;s values. I.E. you want to change a field from VARCHAR(255) NOT NULL to VARCHAR(50).</p>
<p>There is also a way to re-arrange the column order in a table but this isn&#8217;t every really needed. If you would really like to do it, <a target="_blank" href="http://dev.mysql.com/doc/refman/5.0/en/change-column-order.html">you can read more about it here</a>.</p>
<p><strong>Insert, updating and removing specific rows</strong></p>
<p><code>INSERT INTO `table_name` VALUES ('value_1', 'value_2', 'value_3','value_4');</code></p>
<p><code>UPDATE `table_name` SET `field_name` = 'new value', `another_field_name` = 'another new value' WHERE `id` = 56;</code></p>
<p><code>DELETE FROM `table_name` WHERE `id` = 56;</code></p>
<p>The first query is used to insert a new record into a table. If you insert a new record this way, without specifying which fields you are giving values for, you HAVE to give values for every field. If you only want to insert values for certain fields, you can use the following query:</p>
<p><code>INSERT INTO `table_name` (`field_1`, `field_2`, `field_5`) VALUES ('field_1_value', 'field_2_value', 'field_3_value');</code></p>
<p>If you want to insert multiple rows at once you can have a comma separated list of values, I.E.:</p>
<p><code>INSERT INTO `table_name` VALUES ('value_1', 'value_2', 'value_3','value_4'),('value_1', 'value_2', 'value_3','value_4'),('value_1', 'value_2', 'value_3','value_4');</code></p>
<p><code>INSERT INTO `table_name` (`field_1`, `field_2`, `field_5`) VALUES ('field_1_value', 'field_2_value', 'field_3_value'),('field_1_value', 'field_2_value', 'field_3_value'),('field_1_value', 'field_2_value', 'field_3_value');</code></p>
<p>If you are inserting a value for an auto incremented field, you should enter NULL.</p>
<p>The UPDATE query above is for updating an existing row, it consists of a comma separated list of field = value pairs and a WHERE clause to specify which row(s) to update. The list of field = value pairs can contain as many fields as you want.</p>
<p>The DELETE query above is the same as the one mentioned before for emptying a table except it now has a WHERE clause which is used to delete one selection of rows.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2008/08/06/mysql-basic-reference/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flex 3 DataGrid double click event</title>
		<link>http://blog.s-gray.com/2008/08/06/flex-3-datagrid-double-click-event/</link>
		<comments>http://blog.s-gray.com/2008/08/06/flex-3-datagrid-double-click-event/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 11:52:26 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[datagrid]]></category>
		<category><![CDATA[double click]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[flex 3]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=26</guid>
		<description><![CDATA[I&#8217;ve just had a thought that it was hard to come accross resources for handling double click events on DataGrids in Flex 3.
There are lots of tutorials on how to handle them in Flex 2 but this doesn&#8217;t apply for Flex 3, as Flex 3 natively handles double click events and Flex 2 did not.
There [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just had a thought that it was hard to come accross resources for handling double click events on DataGrids in Flex 3.</p>
<p>There are lots of tutorials on how to handle them in Flex 2 but this doesn&#8217;t apply for Flex 3, as Flex 3 natively handles double click events and Flex 2 did not.</p>
<p>There are also a lot of tutorials on how to amend functionality so that you have to double click to edit a row instead of the default single click. This tutorial does not cover this, this tutorial covers functionality of double clicking a row and then triggering something. I.E. a table of products, you want to double click a row to view product details etc.</p>
<p>First off, we need to make a slight amendment to our DataGrid (or AdvancedDataGrid, same applies to both):</p>
<p><code>&lt;mx:DataGrid id=&quot;MyDataGrid&quot; doubleClickEnabled=&quot;true&quot; itemDoubleClick=&quot;functionName(event);&quot;&gt;<br />
...</code></p>
<p>There are obvious meanings to both of these new attributes; doubleClickEnabled is used to tell Flex we want to allow/handle double click events on this DataGrid and itemDoubleClick tells Flex which function to use.</p>
<p>The above function should look something like:</p>
<p><code>protected function functionName(event:ListEvent):void<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;var selectedRow:Object = event.currentTarget.selectedItem;<br />
&nbsp;&nbsp;&nbsp;&nbsp;Alert.show(selectedRow.myVariableName);<br />
}</code></p>
<p>You can directly access the selected row from the DataGrid using the event.currentTarget.selectedItem reference. You can then access any variable that exists in the DataGrid&#8217;s dataProvider for that row.</p>
<p>Of course to get the above working you&#8217;ll need to:</p>
<p><code>import mx.controls.Alert;</code><br />
<code>import mx.events.ListEvent;</code></p>
<p>Stephen.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2008/08/06/flex-3-datagrid-double-click-event/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>jQuery wildcard selectors</title>
		<link>http://blog.s-gray.com/2008/08/05/jquery-wildcard-selectors/</link>
		<comments>http://blog.s-gray.com/2008/08/05/jquery-wildcard-selectors/#comments</comments>
		<pubDate>Tue, 05 Aug 2008 16:02:13 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[selector]]></category>
		<category><![CDATA[wildcard]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=13</guid>
		<description><![CDATA[UPDATE: The below method no longer works! Go here to see a tested, working method: http://ropox.net/archives/1081
This is the first tutorial on my blog. We&#8217;re going to start with something simple and it&#8217;s only useful if you use jQuery.
When I started using jQuery I found it hard to find information on using wildcards when selecting DOM [...]]]></description>
			<content:encoded><![CDATA[<p><strong><span style="color:#ff0000;">UPDATE:</span> The below method no longer works! Go here to see a tested, working method: <a href="http://ropox.net/archives/1081">http://ropox.net/archives/1081</a></strong></p>
<p>This is the first tutorial on my blog. We&#8217;re going to start with something simple and it&#8217;s only useful if you use jQuery.</p>
<p>When I started using jQuery I found it hard to find information on using wildcards when selecting DOM elements.</p>
<p>After a while you get to understand that jQuery allows the use of regular expressions in a lot of places, I.E. when selecting like this:</p>
<p><code>$('#myElement').html();</code></p>
<p>So with this in mind, you can use \\S* to make wildcard selections, I.E.:</p>
<p><code>$('#myEle\\S*').each();</code></p>
<p>Stephen.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2008/08/05/jquery-wildcard-selectors/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

