<?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>Leoganda.net &#187; Tutorial</title>
	<atom:link href="http://www.leoganda.net/category/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.leoganda.net</link>
	<description></description>
	<lastBuildDate>Tue, 25 May 2010 16:33:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>XML-RPC on IPhone</title>
		<link>http://www.leoganda.net/xml-rpc-on-iphone/</link>
		<comments>http://www.leoganda.net/xml-rpc-on-iphone/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 12:38:18 +0000</pubDate>
		<dc:creator>leoganda</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[IPhone]]></category>
		<category><![CDATA[XMLRPC]]></category>

		<guid isPermaLink="false">http://www.leoganda.net/?p=28</guid>
		<description><![CDATA[Hi, after play along to implement XML-RPC on IPhone finally I made it. I tried googling to find some articles that related to XML-RPC on IPhone, and those article drag me to WordPress application for IPhone. This application using XML RPC to communicate IPhone with the WordPress Blog, so the idea is grab the XML-RPC [...]]]></description>
			<content:encoded><![CDATA[<p>Hi, after play along to implement XML-RPC on IPhone finally I made it. I tried googling to find some articles that related to XML-RPC on IPhone, and those article drag me to WordPress application for IPhone. This application using XML RPC to communicate IPhone with the WordPress Blog, so the idea is grab the XML-RPC function from the WP application and implement it on our application. First we need to download WordPress for IPhone source code, you can <a href="http://iphone.trac.wordpress.org/changeset/336/tags/1.21?old_path=%2F&amp;format=zip" target="_blank">download it here.</a><span id="more-28"></span></p>
<p>Once you download the source code, extract it. You will find a folder named Class, under the Class folder you will find XMLRPC folder. We need to import this folder (with the file inside) to our project, and also import <strong>NSString+XMLExtensions.h</strong> and <strong>NSString+XMLExtensions.m.</strong></p>
<p>I will show you how to implement this XML-RPC on simple application.</p>
<p>Start your XCode program, make new &#8220;View-based Application&#8221; project.</p>
<p><a href="http://www.leoganda.net/wp-content/uploads/2009/08/Picture-1.png"><img title="Picture 1" src="http://www.leoganda.net/wp-content/uploads/2009/08/Picture-1.png" alt="Picture 1" width="409" height="159" /></a></p>
<p>Name the project with &#8220;XMLRPC-sayHello&#8221;.</p>
<p><a href="http://www.leoganda.net/wp-content/uploads/2009/08/Picture-2.png"><img title="Picture 2" src="http://www.leoganda.net/wp-content/uploads/2009/08/Picture-2.png" alt="Picture 2" width="480" height="93" /></a></p>
<p>Once the workspace opened, import the XMLRPC folder from WordPress source code to our project. Right click on Class folder, Add-&gt;Existing files</p>
<p><a href="http://www.leoganda.net/wp-content/uploads/2009/08/Picture-3.png"><img title="Picture 3" src="http://www.leoganda.net/wp-content/uploads/2009/08/Picture-3.png" alt="Picture 3" width="454" height="206" /></a></p>
<p>Then browse to the WordPress for Iphone source code, and select the XMLRPC folder. Click the &#8220;Add&#8221; button. The next is import the <strong>NSString+XMLExtensions.h</strong> and <strong>NSString+XMLExtensions.m </strong>files to our project.</p>
<p>Your project files will be look like this.</p>
<p><a href="http://www.leoganda.net/wp-content/uploads/2009/08/Picture-4.png"><img title="Picture 4" src="http://www.leoganda.net/wp-content/uploads/2009/08/Picture-4.png" alt="Picture 4" width="295" height="423" /></a></p>
<p>Ok the import step is done, now we need to design UI. We will make a simple interface with Label and Button only. The final design will be look like this.</p>
<p><a href="http://www.leoganda.net/wp-content/uploads/2009/08/Picture-5.png"><img title="Picture 5" src="http://www.leoganda.net/wp-content/uploads/2009/08/Picture-5-154x300.png" alt="Picture 5" width="154" height="300" /></a></p>
<p>To design the UI, double click the XMLRPC_SayHelloViewController.xib file and the interface builder will show up. On interface builder Drag a label from the library and change the text to &#8220;Response&#8221;. Next drag the Round Rect Button, and change the text to &#8220;Get Response&#8221;. Once done, close the interface builder and back to XCode.</p>
<h3>Coding</h3>
<p>Open the XMLRPC_SayHelloViewController.h, we will import the header files that used for XMLRPC, that are XMLRPCResponse.h, XMLRPCRequest.h, and XMLRPCConection.h. We also declare the label and the getResponse method in our header file. It should be look like this.</p>
<p><a href="http://www.leoganda.net/wp-content/uploads/2009/08/Picture-7.png"><img title="Picture 7" src="http://www.leoganda.net/wp-content/uploads/2009/08/Picture-7.png" alt="Picture 7" width="382" height="215" /></a></p>
<p>Once you done with the XMLRPC_SayHelloViewController.h, double click the XMLRPC_SayHelloViewController.xib to reopen the interface builder, we will connect the code with the interface. Open the Inspector window first Tools-&gt;Inspector.</p>
<p>Click the Response label in designer, then in the Inspector window it will be shown &#8220;New Referencing Outlet&#8221;. Drag the right circle of &#8220;New Referencing Outlet&#8221; to File&#8217;s Owner. See image.</p>
<p><a href="http://www.leoganda.net/wp-content/uploads/2009/08/Picture-81.png"><img title="Picture-8" src="http://www.leoganda.net/wp-content/uploads/2009/08/Picture-81.png" alt="Picture-8" width="618" height="303" /></a></p>
<p>When you release the mouse button, choose the &#8220;lblResponse&#8221; from the pop up window.</p>
<p><a href="http://www.leoganda.net/wp-content/uploads/2009/08/Picture-9.png"><img title="Picture 9" src="http://www.leoganda.net/wp-content/uploads/2009/08/Picture-9.png" alt="Picture 9" width="592" height="151" /></a></p>
<p>Ok, now select the Button on the interface, and drag the right circle button on the &#8220;Touch Down&#8221; inspector window to File&#8217;s Owner.</p>
<p><a href="http://www.leoganda.net/wp-content/uploads/2009/08/Picture-10.png"><img title="Picture 10" src="http://www.leoganda.net/wp-content/uploads/2009/08/Picture-10.png" alt="Picture 10" width="268" height="271" /></a></p>
<p>Once you finished editing the interface, save it and we continue with the coding.</p>
<p>Open the XMLRPC_SayHelloViewController.m and add the following code.</p>
<p><a href="http://www.leoganda.net/wp-content/uploads/2009/08/Picture-11.png"><img title="Picture 11" src="http://www.leoganda.net/wp-content/uploads/2009/08/Picture-11.png" alt="Picture 11" width="585" height="403" /></a></p>
<p>You can change the server path to your own path, and don&#8217;t forget to enable the XMLRPC on your wordpress installation. On wordpress XMLRPC there is demo.sayHello method that returns &#8220;hello&#8221; string, so I used this for the example.</p>
<p>Tadda! It&#8217;s done! Run the emulator by pressing command+enter button. Once running, press the &#8220;Get Response&#8221; button, that will invoke the getResponse method and show up the result to lblResponse.</p>
<p><a href="http://www.leoganda.net/wp-content/uploads/2009/08/XMLRPC-SayHello.zip">Download source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.leoganda.net/xml-rpc-on-iphone/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>How to connect MySQL in Prado Framework</title>
		<link>http://www.leoganda.net/how-to-connect-mysql-in-prado-framework/</link>
		<comments>http://www.leoganda.net/how-to-connect-mysql-in-prado-framework/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 16:00:55 +0000</pubDate>
		<dc:creator>leoganda</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Prado]]></category>

		<guid isPermaLink="false">http://www.leoganda.net/?p=8</guid>
		<description><![CDATA[Hello! This is my first article tutorial in this blog, today my friend have a problem connecting SQL databases with PRaDO framework. I have used this framework several years ago, and it&#8217;s quite easy to make a website with Prado. This time I will write how to connect MySQL with Prado, insert data, and display [...]]]></description>
			<content:encoded><![CDATA[<p>Hello!</p>
<p>This is my first article tutorial in this blog, today my friend have a problem connecting SQL databases with PRaDO framework. I have used this framework several years ago, and it&#8217;s quite easy to make a website with Prado. This time I will write how to connect MySQL with Prado, insert data, and display it in the web page.</p>
<p>First, I&#8217;m using XAMPPLITE as webserver, XAMPPLITE is lite version of XAMPP, but if you are using XAMPP it&#8217;s ok. <a title="Download XAMPP" href="http://www.apachefriends.org/en/xampp-windows.html" target="_blank">Download XAMPP</a>.</p>
<p>After you finish the XAMPP download, continue with download Prado framework. <a href="http://www.pradosoft.com/download/" target="_blank">Download Prado</a>.</p>
<p>Install the XAMPP, and extract the prado framework in htdocs folder.</p>
<p>The optional prado-cli.php PHP script file in the framework directory provides command line tools to perform various tedious takes in Prado. The prado-cli.php can be used to create Prado project skeletons, create initial test fixtures, and access to an interactive PHP shell. We will use command line tool to generate our prado project.<span id="more-8"></span></p>
<h3>1. Make setPath</h3>
<p>First I made setpath.bat to declare PHP path, so we can called any file in PHP path easier.</p>
<p>Make a file setpath.bat ( I put this file in C:\)</p>
<p><code>PATH=C:\xampplite\php\;</code></p>
<p>set the path to your php directory.</p>
<h3>2. Generate the Project</h3>
<p>Open the command prompt, and execute the setpath.bat by typing the filename setpath.bat</p>
<p><a href="http://www.leoganda.net/wp-content/uploads/2009/07/1-setpath.jpg"><img class="alignnone size-full wp-image-9" title="1 setpath" src="http://www.leoganda.net/wp-content/uploads/2009/07/1-setpath.jpg" alt="1 setpath" width="668" height="333" /></a></p>
<p>Go to htdocs</p>
<p><a href="http://www.leoganda.net/wp-content/uploads/2009/07/2-htdocs.jpg"><img class="alignnone size-full wp-image-10" title="2 htdocs" src="http://www.leoganda.net/wp-content/uploads/2009/07/2-htdocs.jpg" alt="2 htdocs" width="668" height="333" /></a></p>
<p>Let&#8217;s generate project, execute this line</p>
<p><code>php C:\xampplite\htdocs\prado\framework\prado-cli.php -c pradocontact</code></p>
<p>When the generate success the command line will display line like this</p>
<p><a href="http://www.leoganda.net/wp-content/uploads/2009/07/3-generate-project.jpg"><img class="alignnone size-full wp-image-11" title="3 generate project" src="http://www.leoganda.net/wp-content/uploads/2009/07/3-generate-project.jpg" alt="3 generate project" width="668" height="333" /></a></p>
<h3>3. Open in browser</h3>
<p>Open your browser and navigate to http://localhost/pradocontact/ if you see the prado welcome page, congratulations you have been generate prado project successly.</p>
<p><a href="http://www.leoganda.net/wp-content/uploads/2009/07/4-welcome-to-prado.jpg"><img class="alignnone size-full wp-image-12" title="4 welcome to prado" src="http://www.leoganda.net/wp-content/uploads/2009/07/4-welcome-to-prado.jpg" alt="4 welcome to prado" width="516" height="228" /></a></p>
<h3>4. Create Database</h3>
<p>Navigate to http://localhost/phpmyadmin/ and create new database. Type &#8220;pradocontact&#8221; in create new database field and hit create button.<br />
<a href="http://www.leoganda.net/wp-content/uploads/2009/07/5-create-database.jpg"><img src="http://www.leoganda.net/wp-content/uploads/2009/07/5-create-database.jpg" alt="5 create database" title="5 create database" width="578" height="260" class="alignnone size-full wp-image-13" /></a><br />
Then make a new table called &#8220;contact&#8221; with 2 field (id and name). Set the id field type into tinyint, auto_increment, and as primary key. Set the field name type as varchar and give the length 100.<br />
<a href="http://www.leoganda.net/wp-content/uploads/2009/07/6-create-table.jpg"><img src="http://www.leoganda.net/wp-content/uploads/2009/07/6-create-table.jpg" alt="6 create table" title="6 create table" width="439" height="122" class="alignnone size-full wp-image-14" /></a><br />
<a href="http://www.leoganda.net/wp-content/uploads/2009/07/7-field-table.jpg"><img src="http://www.leoganda.net/wp-content/uploads/2009/07/7-field-table.jpg" alt="7 field table" title="7 field table" width="554" height="104" class="alignnone size-full wp-image-15" /></a></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`contact`</span> <span style="color: #66cc66;">&#40;</span>
<span style="color: #ff0000;">`id`</span> TINYINT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`name`</span> VARCHAR<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">100</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
<span style="color: #66cc66;">&#41;</span> ENGINE <span style="color: #66cc66;">=</span> MYISAM ;
&nbsp;
After the <span style="color: #993333; font-weight: bold;">TABLE</span> created<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #cc66cc;">2</span> rows <span style="color: #993333; font-weight: bold;">DATA</span> <span style="color: #993333; font-weight: bold;">INTO</span> contact <span style="color: #993333; font-weight: bold;">TABLE</span><span style="color: #66cc66;">.</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`contact`</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">`id`</span> <span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`name`</span> <span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span>
<span style="color: #ff0000;">'1'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'leo'</span>
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span>
<span style="color: #ff0000;">'2'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'ganda'</span>
<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<h3>5. Set connection in application.xml</h3>
<p>Browse your project folder and open the protected folder C:\xampplite\htdocs\pradocontact\protected</p>
<p>You will see a file &#8220;application.xml&#8221;, open it and edit.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><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: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;db&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;System.Data.TDataSourceConfig&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;database</span> <span style="color: #000066;">ConnectionString</span>=<span style="color: #ff0000;">&quot;mysql:host=localhost;dbname=pradocontact&quot;</span> <span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;root&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</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>
&nbsp;
  	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;System.Data.ActiveRecord.TActiveRecordConfig&quot;</span> <span style="color: #000066;">ConnectionID</span>=<span style="color: #ff0000;">&quot;db&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</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></pre></div></div>

<p>We make a <strong>ConnectionString </strong>to mysql database, dbname is our database that used for this project. Set the <strong>username </strong>and <strong>password </strong>with your database account.</p>
<h3>6. Create Active Record</h3>
<p>To use active record, I will make a new folder called database inside the protected folder to store the <strong>ActiveRecord </strong>file. After the database folder created, open the <code>application.xml</code> once again, and declare the database path.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;paths<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;using</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">&quot;Application.database.*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/paths<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Your <code>application.xml</code> should be look like this</p>

<div class="wp_syntax"><div class="code"><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>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;application</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;pradocontact&quot;</span> <span style="color: #000066;">mode</span>=<span style="color: #ff0000;">&quot;Debug&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;paths<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;using</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">&quot;Application.database.*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/paths<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- configurations for modules --&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;module</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;db&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;System.Data.TDataSourceConfig&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;database</span> <span style="color: #000066;">ConnectionString</span>=<span style="color: #ff0000;">&quot;mysql:host=localhost;dbname=pradocontact&quot;</span> <span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;root&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</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>
  	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;System.Data.ActiveRecord.TActiveRecordConfig&quot;</span> <span style="color: #000066;">ConnectionID</span>=<span style="color: #ff0000;">&quot;db&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</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;
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- configuration for available services --&gt;</span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;services<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;page&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;TPageService&quot;</span> <span style="color: #000066;">DefaultPage</span>=<span style="color: #ff0000;">&quot;Home&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/services<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- application parameters</span>
<span style="color: #808080; font-style: italic;">  &lt;parameters&gt;</span>
<span style="color: #808080; font-style: italic;">    &lt;parameter id=&quot;param1&quot; value=&quot;value1&quot; /&gt;</span>
<span style="color: #808080; font-style: italic;">    &lt;parameter id=&quot;param2&quot; value=&quot;value2&quot; /&gt;</span>
<span style="color: #808080; font-style: italic;">  &lt;/parameters&gt;</span>
<span style="color: #808080; font-style: italic;">  --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>After you finish editing the <code>application.xml</code>, let&#8217;s generate Active Record from our database in MySQL.<br />
Open the command prompt again, go to C:\xampplite\htdocs\pradocontact\ and execute <code>php C:\xampplite\htdocs\prado\framework\prado-cli.php shell .</code></p>
<p>execute <code>generate contact Application.database.ContactRecord</code></p>
<p><a href="http://www.leoganda.net/wp-content/uploads/2009/07/8-generate-AR.jpg"><img src="http://www.leoganda.net/wp-content/uploads/2009/07/8-generate-AR.jpg" alt="8 generate AR" title="8 generate AR" width="668" height="333" class="alignnone size-full wp-image-16" /></a></p>
<p>Open your database folder with explorer, and you will find a new file called ContactRecord.php, try to open it.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * Auto generated by prado-cli.php on 2009-07-18 03:01:37.
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> ContactRecord <span style="color: #000000; font-weight: bold;">extends</span> TActiveRecord
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">const</span> TABLE<span style="color: #339933;">=</span><span style="color: #0000ff;">'contact'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$name</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> finder<span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">finder</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h3>7. Test The Active Record</h3>
<p>Ok, let test our Active Record using command line tools, type &#8220;ContactRecord::finder()-&gt;findAll()&#8221; and hit enter. See the image below.<br />
<a href="http://www.leoganda.net/wp-content/uploads/2009/07/9-test-AR.jpg"><img src="http://www.leoganda.net/wp-content/uploads/2009/07/9-test-AR.jpg" alt="9 test AR" title="9 test AR" width="668" height="333" class="alignnone size-full wp-image-17" /></a><br />
The command line return an array with 2 record from the mySQL database and that means our activeRecord running well!</p>
<h3>8. Edit Home.page</h3>
<p>paste this code on your Home.page file<br />
<code><br />
&lt;%@ Title="Contact List" %&gt;</p>
<p>&lt;h1&gt;Contact List&lt;/h1&gt;</p>
<p>&lt;a href="&lt;%= $this-&gt;Service-&gt;constructUrl('insert')%&gt;"&gt;Create New Contact&lt;/a&gt;<br />
&lt;br/&gt;</p>
<p>&lt;com:TDataGrid ID="UserGrid"<br />
DataKeyField="id"<br />
AutoGenerateColumns="false"<br />
&gt;</p>
<p>&lt;com:TBoundColumn<br />
HeaderText="ID"<br />
DataField="id" /&gt;</p>
<p>&lt;com:TBoundColumn<br />
HeaderText="Name"<br />
DataField="name" /&gt;</p>
<p>&lt;/com:TDataGrid&gt;<br />
</code></p>
<h3>9. Make new file Home.php</h3>
<p>Paste this code on your Home.php</p>

<div class="wp_syntax"><div class="code"><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> Home <span style="color: #000000; font-weight: bold;">extends</span> TPage
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * Populates the datagrid with user lists.
     * This method is invoked by the framework when initializing the page
     * @param mixed event parameter
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> onInit<span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span><span style="color: #004000;">onInit</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// fetches all data account information</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">UserGrid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DataSource</span><span style="color: #339933;">=</span>ContactRecord<span style="color: #339933;">::</span><span style="color: #004000;">finder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// binds the data to interface components</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">UserGrid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dataBind</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;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h3>10. Make a new file insert.page</h3>
<p><code><br />
&lt;%@ Title="Insert Contact" %&gt;</p>
<p>&lt;com:TForm&gt;</p>
<p>&lt;h1&gt;Insert Contact&lt;/h1&gt;</p>
<p>&lt;span&gt;Name:&lt;/span&gt;<br />
&lt;br/&gt;<br />
&lt;com:TTextBox ID="Name" /&gt;</p>
<p>&lt;com:TButton Text="Create" OnClick="createButtonClicked" /&gt;</p>
<p>&lt;/com:TForm&gt;<br />
</code></p>
<h3>11. Make a new file insert.php</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> insert <span style="color: #000000; font-weight: bold;">extends</span> TPage
<span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> createButtonClicked<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sender</span><span style="color: #339933;">,</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">IsValid</span><span style="color: #009900;">&#41;</span>  <span style="color: #666666; font-style: italic;">// when all validations succeed</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// populates a UserRecord object with user inputs</span>
            <span style="color: #000088;">$ContactRecord</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> ContactRecord<span style="color: #339933;">;</span>
            <span style="color: #000088;">$ContactRecord</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Name</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Text</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
            <span style="color: #666666; font-style: italic;">// saves to the database via Active Record mechanism</span>
            <span style="color: #000088;">$ContactRecord</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// redirects the browser to the homepage</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Service</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DefaultPageUrl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><a href="http://www.leoganda.net/wp-content/uploads/2009/07/10-file-structure.jpg"><img src="http://www.leoganda.net/wp-content/uploads/2009/07/10-file-structure.jpg" alt="10 file structure" title="10 file structure" width="497" height="337" class="alignnone size-full wp-image-18" /></a></p>
<p>Navigate your browser to <code>http://localhost/pradocontact/ </code>you will see this page<br />
<a href="http://www.leoganda.net/wp-content/uploads/2009/07/11-final.jpg"><img src="http://www.leoganda.net/wp-content/uploads/2009/07/11-final.jpg" alt="11 final" title="11 final" width="506" height="311" class="alignnone size-full wp-image-19" /></a></p>
<p>Ok, thanks for reading. Have a nice day! <img src='http://www.leoganda.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://www.leoganda.net/source/pradocontact.rar">Download Source</a><br />
<a href="http://www.leoganda.net/source/pradocontact.sql">Download SQL</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.leoganda.net/how-to-connect-mysql-in-prado-framework/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
