Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
aa1aa84b
Commit
aa1aa84b
authored
Jul 30, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
1a18acb7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
101 deletions
+0
-101
user-management-system.txt
...ew/docs/en/real-world-examples/user-management-system.txt
+0
-101
No files found.
manual/new/docs/en/real-world-examples/user-management-system.txt
View file @
aa1aa84b
In the following example we make a user management system where
# Each user and group are entities
# User is an entity of type 0
# Group is an entity of type 1
# Each entity (user/group) has 0-1 email
# Each entity has 0-* phonenumbers
# If an entity is saved all its emails and phonenumbers are also saved
# If an entity is deleted all its emails and phonenumbers are also deleted
# When an entity is created and saved a current timestamp will be assigned to 'created' field
# When an entity is updated a current timestamp will be assigned to 'updated' field
# Entities will always be fetched in batches
<code type="php">
class Entity extends Doctrine_Record
{
public function setUp()
{
$this->ownsOne('Email', 'Entity.email_id');
$this->ownsMany('Phonenumber', 'Phonenumber.entity_id');
$this->setAttribute(Doctrine::ATTR_LISTENER, new EntityListener());
}
public function setTableDefinition()
{
$this->hasColumn('name', 'string', 50);
$this->hasColumn('loginname', 'string', 20);
$this->hasColumn('password', 'string', 16);
}
}
class Group extends Entity
{
public function setUp()
{
parent::setUp();
$this->hasMany('User', 'Groupuser.user_id');
$this->setInheritanceMap(array('type'=>1));
}
}
class User extends Entity
{
public function setUp()
{
parent::setUp();
$this->hasMany('Group', 'Groupuser.group_id');
$this->setInheritanceMap(array('type'=>0));
}
}
class Groupuser extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('group_id', 'integer');
$this->hasColumn('user_id', 'integer');
}
}
class Phonenumber extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('phonenumber', 'string', 20);
$this->hasColumn('entity_id', 'integer');
}
}
class Email extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('address', 'string', 150, 'email|unique');
}
}
class EntityListener extends Doctrine_EventListener
{
public function onPreUpdate(Doctrine_Record $record)
{
$record->updated = time();
}
public function onPreInsert(Doctrine_Record $record)
{
$record->created = time();
}
}
// USER MANAGEMENT SYSTEM IN ACTION:
$manager = Doctrine_Manager::getInstance();
$conn = $manager->openConnection(new PDO('DSN','username','password'));
$user = new User();
$user->name = 'Jack Daniels';
$user->Email->address = 'jackdaniels@drinkmore.info';
$user->Phonenumber[0]->phonenumber = '123 123';
$user->Phonenumber[1]->phonenumber = '133 133';
$user->save();
$user->Group[0]->name = 'beer lovers';
$user->Group[0]->Email->address = 'beerlovers@drinkmore.info';
$user->Group[0]->save();
</code>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment