> 1. Create the model classes
2. Create a test
3. Create the PersistenceObjects
4. Describe the classes
5. Configure DatabaseManager and create the database
6. Use the PersistenceObjects in your controllers
7. Add database-methods
1. Create the model classes
A class should be created for each object that need to be stored in the database. In this example we need three classes:
- User
- Album
- Picture
The following rules need to be remembered here:
- Each class needs an id attribute.
- A setter and getter needs to be created for each attribute that is stored in the database.
- It is required to use camelCase for each classname, property-name and function-name.
class User { private $userName; private $id = null; private $userRole = 0; private $password = ""; private $albums = array(); private $favouritesAlbum; public function User() { $this->favouritesAlbum = new Album(); } public function getId() { return $this->id; } public function setId($value) { $this->id = $value; return $this; } .... }
class Album { private $id = null; private $name = ""; private $description; private $pictures = array(); public function Album() { } ... }
class Picture { private $id = null; private $name; private $description; private $url; private $albums = array(); public function Picture() { } ... }previous - Introduction
next - Create a test