Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Admin extends User
- {
- // Other methods
- public function save()
- {
- parent::save();
- // now save your additional fields wherever they need to go
- }
- }
- $entity = new Admin;
- $mapper = new AdminMapper( $db );
- $entity->setName('Wintermute');
- $mapper->fetch( $entity );
- //retrieve data for admin with that name
- $entity->setName('Neuromancer');
- $mapper->store( $entity );
- // rename and save
- class User
- {
- public function Save()
- {
- $savestuff = $this->GetProperties();
- // do save acctions
- }
- protected function GetProperties()
- {
- return 'user prop';
- }
- }
- class Admin Extends User
- {
- protected function GetProperties()
- {
- return 'admin prop';
- }
- }
- class Admin
- {
- public function save(Model_Abstract $model = null)//type hinting
- {
- if ($model instanceof Model_Admin)
- {
- //do admin insert/update stuff here
- return;
- }
- parent::save($model);//call regular method
- }
- }
- class BasicEntity
- {
- protected $tablename;
- protected $schema;
- public function update()
- {
- $fields = "";
- $placeholders = "";
- foreach($this -> schema as $field => $type)
- {
- // you join the fields here to get something like ('username', 'email', 'enabled', 'createdAt', 'password')
- // then you write your PDO statement providing placeholders like (:?, :?, :?, :?, :?)
- // you'll have to bind parameters based on their $type [int, string, date]
- }
- $query = sprintf(
- "UPDATE %s SET VALUES(%s) = %s",
- $this -> tablename,
- $fields,
- $placeholders
- );
- // execute statement here, handle exceptions, and so...
- }
- }
- class User extends BasicEntity
- {
- protected $id;
- protected $username;
- protected $email;
- protected $password;
- protected $enabled;
- protected $createdAt;
- public function __construct()
- {
- $this -> tablename = '_user';
- $this -> schema = array(
- 'id' => 'int',
- 'username' => 'string',
- 'email' => 'string',
- 'password' => 'string',
- 'enabled' => 'int',
- 'createdAt' => 'datetime'
- );
- }
- }
- class Admin extends User
- {
- protected $additionalProperty;
- public function __construct()
- {
- parent::__construct();
- $this -> schema['additionalProperty'] = 'string';
- }
- }
Add Comment
Please, Sign In to add comment