PersistenceObjects for php

3. Create the PersistenceObjects

Now we need to extend PersistenceObject-class for each managed class we have. In this case we create three Persistenceclasses:

Let's begin with the UserPersistence-class.

require_once dirname(__FILE__)."../lib/persistenceobjects/classes.php";
require_once dirname(__FILE__)."/../model/User.php";
require_once dirname(__FILE__)."/../model/Album.php";
require_once dirname(__FILE__)."/../model/Picture.php";

class UserPersistence extends PersistenceObject {
	
	public function UserPersistence() {
		
		$this->tableName = "user";
		$this->className = "User";
		
		parent::PersistenceObject(func_get_args());

	}
}

What happens here is that:

Remember to be case sensitive here!!!

Lets do the same for the rest of the classes:

require_once dirname(__FILE__)."../lib/persistenceobjects/classes.php";
require_once dirname(__FILE__)."/../model/User.php";
require_once dirname(__FILE__)."/../model/Album.php";
require_once dirname(__FILE__)."/../model/Picture.php";

class AlbumPersistence extends PersistenceObject {
	
	public function AlbumPersistence() {
		
		$this->tableName = "album";
		$this->className = "Album";
		
		parent::PersistenceObject(func_get_args());
		
	}
	
}
require_once dirname(__FILE__)."../lib/persistenceobjects/classes.php";
require_once dirname(__FILE__)."/../model/User.php";
require_once dirname(__FILE__)."/../model/Album.php";
require_once dirname(__FILE__)."/../model/Picture.php";

class PicturePersistence extends PersistenceObject {
	
	public function PicturePersistence() {
		
		$this->tableName = "picture";
		$this->className = "Picture";
		
		parent::PersistenceObject(func_get_args());

	}
	
}

Now if you run the test you should get an Exception that says UserPersistence has no PropertyDescriptions. Let's attend to that.

previous - Create a test
next - Describe the classes