Joomla Security

We will protect your Joomla website from malicious attack. Read more...

Site Admin

We will doing regular admin for your website, including regular backup, joomla update, joomla extensions install/update, security and optimization. Read more...

PSD to Joomla

You doing the design, I convert it into Joomla site. Read more...
Home Joomla Customization Programming in Joomla 1.5 way
Programming in Joomla 1.5 way

Joomla 1.5 provide a JTabless class for creating,reading,updating, and deleting records in the database table, it's easy to save data into database:

$row = &JTable::getInstance('table_name');
$row->bind($data_array);
$row->store();

Create a new article is a bit complex, now we use the previous method to create article into database:

$row = &JTable::getInstance('content');
$row->bind($data_array);

// sanitise id field
$row->id = (int) $row->id;

$isNew = true;
$user = &JFactory::getUser();
$row->created-by = $user->get('id');

$datenow = &JFactory::getDate();
$row->created = $datenow->toMySQL();
$row->publish_up = $row->created;
$row->publish_down = $db->getNullDate();

$row->state = 0;
$row->params = null;
$row->attribs = "";
$row->metadata = "";

// Prepare the content for saving to the database
ContentHelper::saveContentPrep($row);

if ($row->check()) {
  JError::raiseError(500, $db->stderr());
  return false;
}

// Increment the content version number
$row->version++; 

$dispatcher = &JDispatcher::getInstance();
$result = $dispatcher->trigger('onBeforeContentSave', array($row, $isNew);
if(in_array(false, $result, true)) {
  JError::raiseError(500, $row->getError());
  return false;
}

// Store the content to the database
if (!$row->store()) {
  JError::raiseError(500, $db->stderr());
  return false;
}

// Check the article and update item order
$row->checkin();
$row->reorder('catid = '.(int) $row->catid.' AND state >= 0');

$dispatcher->trigger('onAfterContentSave', array(&$row, $isNew));
 
Joomla template made by HeJian