10.04.2018 Views

Doctrine_manual-1-2-en

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 31: Real World Examples 374<br />

Chapter 31<br />

Real World Examples<br />

Listing<br />

31-1<br />

User Managem<strong>en</strong>t System<br />

In almost all applications you need to have some kind of security or auth<strong>en</strong>tication system<br />

where you have users, roles, permissions, etc. Below is an example where we setup several<br />

models that give you a basic user managem<strong>en</strong>t and security system.<br />

class User ext<strong>en</strong>ds <strong>Doctrine</strong>_Record<br />

{<br />

public function setTableDefinition()<br />

{<br />

$this->hasColumn('username', 'string', 255, array(<br />

'unique' => true<br />

)<br />

);<br />

$this->hasColumn('password', 'string', 255);<br />

}<br />

}<br />

class Role ext<strong>en</strong>ds <strong>Doctrine</strong>_Record<br />

{<br />

public function setTableDefinition()<br />

{<br />

$this->hasColumn('name', 'string', 255);<br />

}<br />

}<br />

class Permission ext<strong>en</strong>ds <strong>Doctrine</strong>_Record<br />

{<br />

public function setTableDefinition()<br />

{<br />

$this->hasColumn('name', 'string', 255);<br />

}<br />

}<br />

class RolePermission ext<strong>en</strong>ds <strong>Doctrine</strong>_Record<br />

{<br />

public function setTableDefinition()<br />

{<br />

$this->hasColumn('role_id', 'integer', null, array(<br />

'primary' => true<br />

)<br />

----------------- Brought to you by

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!