Guides > Object Relational Mapping

Introducing The ORM Component

The Object Relational Mapping Component is a great and elegant tool for retrieving and manipulating database tables data with just a couple of lines of code. The class can be used with the PtcEvent component to add event listeners to queries. This class can also be used to call methods from the PtcQueryBuilder component directly. Retrieved rows can be converted to arrays or json arrays. The PtcMapper can also use shortcut methods to retrieve / update single column values.

Main Features:

  • Simple syntax to manipulate and insert rows
  • Uses shortcuts to retrieve / update single column value
  • Can be used with PtcEvent component to add event listeners to queries
  • Uses the PtcQueryBuilder class to handle all queries
  • Retrieved records can be easily converted to json arrays
  • Can use any connection configured with the PtcDb class
** This component depends on the PtcDb and the PtcQueryBuilder components, therefore it is not stand-alone.

Getting Started

To start using the Object Relational Mapping component, alll we need to do is include the file PtcMapper.php and create an extended class:

  1. // the database table name will be the class name
  2. class MY_Table extends PtcMapper
  3. {
  5. }
The PtcMapper will use the class name as the database table name in lowercase letters.
Now that we have extended the component, we can start inserting and updating records for the table:
  1. // getting record by id
  2. $row = MY_Table::find( 1 );
  4. print $row->some_column;
  5. print $row->some_other_column;
That should get you started with the ORM component.
For a complete list of options and examples read the full user guide.

**If you like this class, help the project to grow by rating or writing a review at one of the following sites:

⇑Back to Top⇑