eZ Community » Learn » eZ Publish » A Quick and Friendly Introduction to...

A Quick and Friendly Introduction to eZPersistentObject

Thursday 18 November 2010 6:11:37 pm

  • Currently 5 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

In this tutorial we will learn how to use CRUDfeatures by extending eZPersistentObject class, so it will be possible to Create, Read, Update, and Delete objects in the database in a straightforward way, without writing SQL queries.

 

Introduction

Friends are cool, friendly eZ publish API classes too, one of those classes is the eZPersistentObject, do you know it? No? But you should! You can avoid a lot of headaches with your data living inside a database if you learn how to deal with this class. It is a central class of the eZ publish kernel and is responsible to persist objects to the database without all the complex and boring SQL stuff, by using an Object Oriented approach instead. You can view this class as an abstraction layer between the application and the eZDB database interface, a mediator that makes possible to create, read, update, and remove data in the database without worrying with low-level database code. Almost all the classes that store simple data in the eZ Publish database extend it.

You can see the usage of the eZPersistentObject class in:

  • Complex datatypes like eZBinayFile or eZStarRating;
  • Most others kernel central classes extends this class, like eZContentObject, eZContentClass, eZSection, and eZRole;
  • Most of the eZ publish kernel modules use classes that extends eZPersistentObject;
  • Extensions that has custom database tables should use this class.

When developing complex extensions it will become fundamental to understand this class and its usage(s) so you can use its facilities all the time. In this tutorial we will learn about this class in 3 Steps.

  1. Create a sample database table;
  2. Create a class that extends eZPersistentObject class to manipulate the table;
  3. Test our class doing common database table manipulation tasks.
 

Pre-requisites and target population

This tutorial is intended for eZ publish intermediate users who know the basics of extension development. It is recommended to have some knowledge about SQL queries , and database transactions.

 
36 542 Users on board!

Tutorial menu

Printable

Printer Friendly version of the full article on one page with plain styles

Author(s)

Proudly Developed with from