1
0
mirror of synced 2025-01-17 22:11:41 +03:00

Fixed some docs. Mainly substituting " with ' in code examples.

This commit is contained in:
meus 2007-04-11 20:13:39 +00:00
parent 7f68e096b1
commit 70caab1584
22 changed files with 140 additions and 139 deletions

View File

@ -1,34 +0,0 @@
<?php
class Email extends Doctrine_Record {
public function setTableDefinition() {
// setting custom table name:
$this->setTableName('emails');
$this->hasColumn("address", // name of the column
"string", // column type
"200", // column length
array("notblank" => true,
"email" => true // validators / constraints
)
);
$this->hasColumn("address2", // name of the column
"string", // column type
"200", // column length
// validators / constraints without arguments can be
// specified also as as string with | separator
"notblank|email"
);
// Doctrine even supports the following format for
// validators / constraints which have no arguments:
$this->hasColumn("address3", // name of the column
"string", // column type
"200", // column length
array("notblank", "email")
);
}
}
?>

View File

@ -1,7 +1,8 @@
<?php
class User extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("uid","integer",20,"primary|autoincrement");
$this->hasColumn('uid','integer',20,'primary|autoincrement');
}
}
?>

View File

@ -1,8 +1,8 @@
<?php
class Groupuser extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("user_id", "integer", 20, "primary");
$this->hasColumn("group_id", "integer", 20, "primary");
$this->hasColumn('user_id', 'integer', 20, 'primary');
$this->hasColumn('group_id', 'integer', 20, 'primary');
}
}
?>

View File

@ -1,7 +1,7 @@
<?php
class User extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("name","string",200,"primary");
$this->hasColumn('name','string',200,'primary');
}
}
?>

View File

@ -1,18 +1,18 @@
<?php
class User extends Doctrine_Record {
public function setUp() {
$this->ownsMany("Phonenumber","Phonenumber.user_id");
$this->ownsMany('Phonenumber','Phonenumber.user_id');
}
public function setTableDefition() {
$this->hasColumn("name","string",50);
$this->hasColumn("loginname","string",20);
$this->hasColumn("password","string",16);
$this->hasColumn('name','string',50);
$this->hasColumn('loginname','string',20);
$this->hasColumn('password','string',16);
}
}
class Phonenumber extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("phonenumber","string",50);
$this->hasColumn("user_id","integer");
$this->hasColumn('phonenumber','string',50);
$this->hasColumn('user_id','integer');
}
}
?>

View File

@ -1,28 +1,28 @@
<?php
class User extends Doctrine_Record {
public function setUp() {
$this->hasOne("Address","Address.user_id");
$this->ownsOne("Email","User.email_id");
$this->ownsMany("Phonenumber","Phonenumber.user_id");
$this->hasOne('Address','Address.user_id');
$this->ownsOne('Email','User.email_id');
$this->ownsMany('Phonenumber','Phonenumber.user_id');
}
public function setTableDefition() {
$this->hasColumn("name","string",50);
$this->hasColumn("loginname","string",20);
$this->hasColumn("password","string",16);
$this->hasColumn('name','string',50);
$this->hasColumn('loginname','string',20);
$this->hasColumn('password','string',16);
// foreign key column for email ID
$this->hasColumn("email_id","integer");
$this->hasColumn('email_id','integer');
}
}
class Email extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("address","string",150);
$this->hasColumn('address','string',150);
}
}
class Address extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("street","string",50);
$this->hasColumn("user_id","integer");
$this->hasColumn('street','string',50);
$this->hasColumn('user_id','integer');
}
}
?>

View File

@ -1,12 +1,12 @@
<?php
class Task extends Doctrine_Record {
public function setUp() {
$this->hasOne("Task as Parent","Task.parent_id");
$this->hasMany("Task as Subtask","Subtask.parent_id");
$this->hasOne('Task as Parent','Task.parent_id');
$this->hasMany('Task as Subtask','Subtask.parent_id');
}
public function setTableDefinition() {
$this->hasColumn("name","string",100);
$this->hasColumn("parent_id","integer");
$this->hasColumn('name','string',100);
$this->hasColumn('parent_id','integer');
}
}
?>

View File

@ -1,10 +1,10 @@
<?php
class Entity extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("name","string",30);
$this->hasColumn("username","string",20);
$this->hasColumn("password","string",16);
$this->hasColumn("created","integer",11);
$this->hasColumn('name','string',30);
$this->hasColumn('username','string',20);
$this->hasColumn('password','string',16);
$this->hasColumn('created','integer',11);
}
}

View File

@ -1,10 +1,10 @@
<?php
class Entity extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("name","string",30);
$this->hasColumn("username","string",20);
$this->hasColumn("password","string",16);
$this->hasColumn("created","integer",11);
$this->hasColumn('name','string',30);
$this->hasColumn('username','string',20);
$this->hasColumn('password','string',16);
$this->hasColumn('created','integer',11);
}
}

View File

@ -1,26 +1,26 @@
<?php
class User extends Doctrine_Record {
public function setUp() {
$this->hasMany("Group","Groupuser.group_id");
$this->hasMany('Group','Groupuser.group_id');
}
public function setTableDefinition() {
$this->hasColumn("name","string",30);
$this->hasColumn('name','string',30);
}
}
class Group extends Doctrine_Record {
public function setUp() {
$this->hasMany("User","Groupuser.user_id");
$this->hasMany('User','Groupuser.user_id');
}
public function setTableDefinition() {
$this->hasColumn("name","string",30);
$this->hasColumn('name','string',30);
}
}
class Groupuser extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("user_id","integer");
$this->hasColumn("group_id","integer");
$this->hasColumn('user_id','integer');
$this->hasColumn('group_id','integer');
}
}
@ -28,9 +28,9 @@ class Groupuser extends Doctrine_Record {
$user = new User();
// add two groups
$user->Group[0]->name = "First Group";
$user->Group[0]->name = 'First Group';
$user->Group[1]->name = "Second Group";
$user->Group[1]->name = 'Second Group';
// save changes into database
$user->save();
@ -39,11 +39,11 @@ $user->save();
$user->Groupuser->delete();
$groups = new Doctrine_Collection($conn->getTable("Group"));
$groups = new Doctrine_Collection($conn->getTable('Group'));
$groups[0]->name = "Third Group";
$groups[0]->name = 'Third Group';
$groups[1]->name = "Fourth Group";
$groups[1]->name = 'Fourth Group';
$user->Group[2] = $groups[0];
// $user will now have 3 groups

View File

@ -1,16 +1,16 @@
<?php
class User extends Doctrine_Record {
public function setUp() {
$this->hasMany("User as Friend","UserReference.user_id-user_id2");
$this->hasMany('User as Friend','UserReference.user_id-user_id2');
}
public function setTableDefinition() {
$this->hasColumn("name","string",30);
$this->hasColumn('name','string',30);
}
}
class UserReference extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("user_id","integer");
$this->hasColumn("user_id2","integer");
$this->hasColumn('user_id','integer');
$this->hasColumn('user_id2','integer');
}
}
?>

View File

@ -1,24 +1,24 @@
<?php
class Forum_Board extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("name", "string", 100);
$this->hasColumn("description", "string", 5000);
$this->hasColumn('name', 'string', 100);
$this->hasColumn('description', 'string', 5000);
}
public function setUp() {
// notice the 'as' keyword here
$this->ownsMany("Forum_Thread as Threads", "Forum_Thread.board_id");
$this->ownsMany('Forum_Thread as Threads', 'Forum_Thread.board_id');
}
}
class Forum_Thread extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("board_id", "integer", 10);
$this->hasColumn("updated", "integer", 10);
$this->hasColumn("closed", "integer", 1);
$this->hasColumn('board_id', 'integer', 10);
$this->hasColumn('updated', 'integer', 10);
$this->hasColumn('closed', 'integer', 1);
}
public function setUp() {
// notice the 'as' keyword here
$this->hasOne("Forum_Board as Board", "Forum_Thread.board_id");
$this->hasOne('Forum_Board as Board', 'Forum_Thread.board_id');
}
}
$board = new Board();

View File

@ -1,9 +1,9 @@
<?php
$user = new User();
$user->name = "Jack";
$user->name = 'Jack';
$group = $conn->create("Group");
$group->name = "Drinking Club";
$group = $conn->create('Group');
$group->name = 'Drinking Club';
// saves all the changed objects into database

View File

@ -3,9 +3,9 @@ $manager = Doctrine_Manager::getInstance();
// open new connection
$conn = $manager->openConnection(new PDO("dsn","username","password"));
$conn = $manager->openConnection(new PDO('dsn','username','password'));
// getting a table object
$table = $conn->getTable("User");
$table = $conn->getTable('User');
?>

View File

@ -2,7 +2,7 @@
// select all users
$users = $conn->query("FROM User");
$users = $conn->query('FROM User');
// select all users where user email is jackdaniels@drinkmore.info
@ -10,5 +10,5 @@ $users = $conn->query("FROM User WHERE User.Email.address = 'jackdaniels@drinkmo
// using prepared statements
$users = $conn->query("FROM User WHERE User.name = ?", array('Jack'));
$users = $conn->query('FROM User WHERE User.name = ?', array('Jack'));
?>

View File

@ -5,15 +5,15 @@ $manager = Doctrine_Manager::getInstance();
// open first connection
$conn = $manager->openConnection(new PDO("dsn","username","password"), "connection 1");
$conn = $manager->openConnection(new PDO('dsn','username','password'), 'connection 1');
// open second connection
$conn2 = $manager->openConnection(new PDO("dsn2","username2","password2"), "connection 2");
$conn2 = $manager->openConnection(new PDO('dsn2','username2','password2'), 'connection 2');
$manager->getCurrentConnection(); // $conn2
$manager->setCurrentConnection("connection 1");
$manager->setCurrentConnection('connection 1');
$manager->getCurrentConnection(); // $conn

View File

@ -6,13 +6,13 @@ $manager = Doctrine_Manager::getInstance();
// Doctrine_Connection
// a script may have multiple open connections
// (= multiple database connections)
$dbh = new PDO("dsn","username","password");
$dbh = new PDO('dsn','username','password');
$conn = $manager->openConnection();
// or if you want to use Doctrine Doctrine_Db and its
// performance monitoring capabilities
$dsn = "schema://username:password@dsn/dbname";
$dbh = Doctrine_Db::getConnection($dsn);
$dsn = 'schema://username:password@dsn/dbname';
$dbh = Doctrine_Db::getConnection($dsn);
$conn = $manager->openConnection();
?>

View File

@ -2,13 +2,13 @@
// NOTE: related record have always the first letter in uppercase
$email = $user->Email;
$email->address = "jackdaniels@drinkmore.info";
$email->address = 'jackdaniels@drinkmore.info';
$user->save();
// alternative:
$user->Email->address = "jackdaniels@drinkmore.info";
$user->Email->address = 'jackdaniels@drinkmore.info';
$user->save();
?>

View File

@ -1,7 +1,7 @@
<?php
print $user->Email["address"];
print $user->Email['address'];
print $user->Phonenumber[0]->phonenumber;
print $user->Group[0]->get("name");
print $user->Group[0]->name;
?>

View File

@ -1,7 +1,7 @@
<?php
$user->Email["address"] = "koskenkorva@drinkmore.info";
$user->Email['address'] = 'koskenkorva@drinkmore.info';
$user->Phonenumber[0]->phonenumber = "123123";
$user->Phonenumber[0]->phonenumber = '123123';
$user->save();

View File

@ -1,7 +1,41 @@
Setting up a table definition in doctrine is done by using hasColumn method calls inside setTableDefinition method.
Doctrine_Record::hasColumn() takes 4 arguments:<br \>
Doctrine_Record::hasColumn() takes 4 arguments:
1. [<b class="title">column name</b>] <br />
2. [<b class="title">column type</b>] <br />
3. [<b class="title">column length</b>] <br />
4. [<b class="title">column constraints and validators</b>]
# **column name**
# **column type**
# **column length**
# **column constraints and validators**
<code type='php'>
class Email extends Doctrine_Record {
public function setTableDefinition() {
// setting custom table name:
$this->setTableName('emails');
$this->hasColumn('address', // name of the column
'string', // column type
'200', // column length
array('notblank' => true,
'email' => true // validators / constraints
)
);
$this->hasColumn('address2', // name of the column
'string', // column type
'200', // column length
// validators / constraints without arguments can be
// specified also as as string with | separator
'notblank|email'
);
// Doctrine even supports the following format for
// validators / constraints which have no arguments:
$this->hasColumn('address3', // name of the column
'string', // column type
'200', // column length
array('notblank', 'email')
);
}
}
</code>

View File

@ -4,83 +4,83 @@ The entity table has a column called 'type' which tells whether an entity is a g
The only thing we have to do is to create 3 records (the same as before) and add call the Doctrine_Table::setInheritanceMap() method inside the setUp() method.
<code type="php">
<code type='php'>
class Entity extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("name","string",30);
$this->hasColumn("username","string",20);
$this->hasColumn("password","string",16);
$this->hasColumn("created","integer",11);
$this->hasColumn('name','string',30);
$this->hasColumn('username','string',20);
$this->hasColumn('password','string',16);
$this->hasColumn('created','integer',11);
// this column is used for column
// aggregation inheritance
$this->hasColumn("type", "integer", 11);
$this->hasColumn('type', 'integer', 11);
}
}
class User extends Entity {
public function setUp() {
$this->setInheritanceMap(array("type"=>1));
$this->setInheritanceMap(array('type'=>1));
}
}
class Group extends Entity {
public function setUp() {
$this->setInheritanceMap(array("type"=>2));
$this->setInheritanceMap(array('type'=>2));
}
}
</code>
If we want to be able to fetch a record from the Entity table and automatically get a User record if the Entity we fetched is a user we have to do set the subclasses option in the parent class. The adjusted example:
<code type="php">
<code type='php'>
class Entity extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("name","string",30);
$this->hasColumn("username","string",20);
$this->hasColumn("password","string",16);
$this->hasColumn("created","integer",11);
$this->hasColumn('name','string',30);
$this->hasColumn('username','string',20);
$this->hasColumn('password','string',16);
$this->hasColumn('created','integer',11);
// this column is used for column
// aggregation inheritance
$this->hasColumn("type", "integer", 11);
$this->option("subclasses", array("User", "Group");
$this->hasColumn('type', 'integer', 11);
$this->option('subclasses', array('User', 'Group');
}
}
class User extends Entity {
public function setUp() {
$this->setInheritanceMap(array("type"=>1));
$this->setInheritanceMap(array('type'=>1));
}
}
class Group extends Entity {
public function setUp() {
$this->setInheritanceMap(array("type"=>2));
$this->setInheritanceMap(array('type'=>2));
}
}
</code>
We can then do the following given the previous table mapping.
<code type="php">
<code type='php'>
$user = new User();
$user->name="Bjarte S. Karlsen";
$user->username="meus";
$user->password="rat";
$user->name='Bjarte S. Karlsen';
$user->username='meus';
$user->password='rat';
$user->save();
$group = new Group();
$group->name="Users";
$group->username="users";
$group->password="password";
$group->name='Users';
$group->username='users';
$group->password='password';
$group->save();
$q = Doctrine_Query();
$user = $q->from("Entity")->where("id=?")->execute(array($user->id))->getFirst();
$user = $q->from('Entity')->where('id=?')->execute(array($user->id))->getFirst();
$q = Doctrine_Query();
$group = $q->from("Entity")->where("id=?")->execute(array($group->id))->getFirst();
$group = $q->from('Entity')->where('id=?')->execute(array($group->id))->getFirst();
</code>
The user object is here an instance of User while the group object is an instance of Group.