Previously, has created a simple joomla component. Now, create a joomla component that uses a database.
Step One:
Create a table in the joomla database. Because to make the components nyoba, create a table nyoba. the name of the table as a jos_nyoba. Don’t forget this.
Fields: id, title, comment
Step two:
Create programming.
Write in the file nyoba.php and nyoba.html.php.
On file nyoba.php
Add loop
case 'form:
nyoba::form($option);
break;
on file nyoba.html.php
add the function of the form:
form()
{
Echo”
<form method=’post’ action=’index.php?option=com_nyoba&task=insert’>
Insert Title = <input type=’text’ name=’title’>
<br>
Comment = <input type=’text’ name=’comment’>
<input type=’submit’ value=’process’>
</form>
”;
}:
Third Step
Add loop in the file nyoba.php:
case insert:
nyoba::insert($option);
break;
Add insert function in file nyoba.html.php
$title=$_POST[“title”];
$comment=$_POST[“comment”];
$db=& JFactory::getDBO();
$masuk="INSERT INTO #__nyoba values('', '$title', '$comment')";
$db->setQuery( $masuk);
$mlebu=($db->query());
If($mlebu){
Echo”SAVED”;}
Else
{echo”ERROR”;}
Explanation:
$db=& JFactory::getDBO();.
Calling class and function that serves the connection to the database
in php code: mysql_connect("localhost","root","");
mysql_select_db("jos_nyoba");
#__nyoba
in joomla, # _ means the first name of the table. Here name is Jos, so # _ = Jos. If not Jos (for example, jono), then any tables that use the name: jono_nyoba.
$db->setQuery( $masuk);
in php code: mysql_query($masuk);
Tuesday, June 7, 2011
Create Joomla Component, Part 2
6/07/2011 05:15:00 AM
muis arghiansyach gp
No comments
0 komentar:
Post a Comment
Thanks a lot for your attention...