Joomla Table Class for CRUD Operations

The Joomla Table class provides a framework which enables you to do CRUD operations and more on database tables. This class can be used for single record only and it doesn't support SQL operations on multiple records.

1. Insert Record

  • bind() to set the field values
  • check() to perform any validation
  • store() to save the new record to the database

2. Update Record

  • load() to load the existing record from the database, passing the primary key of the record
  • bind() to set the new values for the fields
  • check() to perform any validation
  • store() to save the new values to the database

3. Delete Record

  • load() to load the record
  • delete() to delete it

4. Ordering

Many Joomla items include the concept of ordering. This is governed by a field called ordering in the database table.

getNextOrder(string $where)

This determines the max value of the ordering field among the records included by the optional where clause $where, and returns this max + 1.

reorder(string $where)

This function reads the set of N records defined by the where clause $where, using ORDER BY `ordering` and then writes them back with the ordering fields nicely numbered from 1 to N.

move(integer $delta, string $where)

This function basically finds the record with the next greater (if $delta is positive) or lesser (if $delta is negative) value of the ordering field, and it then swaps the ordering values of the two records.

5. Publish

publish(mixed $pks = null, integer $state = 1, integer $userId)

This sets the publish field to $state for the set of records identified by the $pks array.

6. Hits

hit(mixed $pk = null)

A hits counter is usually used to count the number of times a webpage is visited. In Joomla you can record how many times a component is displayed on the frontend by using adding a hits column to the component's database table, and calling this function each time the component is displayed.

7. Reflection Methods

1. getTableName

It returns the name of the table.

2. getKeyName

It returns the name of the primary key field.

3. getPrimaryKeys

It returns an array of the primary keys and values.

4. getFields

It returns an array of the names of the columns of the database table.

5. hasPrimaryKey

It checks if the primary key has a value set.

6. hasField($name)

It checks if the table has a field of that $name.

Star ActiveStar ActiveStar ActiveStar ActiveStar Inactive