Commit ae738ccb authored by doctrine's avatar doctrine

Some new manual code examples

parent b7bf2265
......@@ -32,6 +32,7 @@ class Doctrine_Form implements Iterator {
if( ! in_array("autoincrement",$e) && ! in_array("protected",$e)) {
if($enum) {
$elements[$column] = "<select name='data[$column]'>\n";
$elements[$column] .= " <option value='-'>-</option>\n";
foreach($enum as $k => $v) {
if($this->record->get($column) == $v) {
$str = 'selected';
......
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine::autoload('Doctrine_Access');
/**
* Doctrine_Hydrate is a base class for Doctrine_RawSql and Doctrine_Query.
* Its purpose is to populate object graphs.
*
*
* @package Doctrine ORM
* @url www.phpdoctrine.com
* @license LGPL
*/
class Doctrine_Hydrate extends Doctrine_Access {
/**
* @var array $fetchmodes an array containing all fetchmodes
......
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine::autoload('Doctrine_Iterator');
class Doctrine_Iterator_Normal extends Doctrine_Iterator {
......
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Validator
* Doctrine_Session uses this class for transaction validation
* Doctrine_Validator performs validations in record properties
*
* @package Doctrine ORM
* @url www.phpdoctrine.com
......
<?php
class Groupuser extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("user_id", "integer" 20, "primary");
$this->hasColumn("group_id", "integer", 20, "primary");
}
}
?>
<?php
class User extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("name","string",200,"primary");
}
}
?>
<?php
class Article extends Doctrine_Record {
public function setTableDefinition() {
// few mapping examples:
// maps into VARCHAR(100) on mysql
$this->hasColumn("title","string",100);
// maps into TEXT on mysql
$this->hasColumn("content","string",4000);
// maps into TINYINT on mysql
$this->hasColumn("type","integer",1);
// maps into INT on mysql
$this->hasColumn("type2","integer",11);
// maps into BIGINT on mysql
$this->hasColumn("type3","integer",20);
// maps into TEXT on mysql
// (serialized and unserialized automatically by doctrine)
$this->hasColumn("types","array",4000);
}
}
?>
<?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
"notblank|email" // validators / constraints
);
}
}
?>
......@@ -2,9 +2,9 @@ Doctrine_Record is the basic component of every doctrine-based project.
There should be atleast one Doctrine_Record for each of your database tables.
Doctrine_Record follows <a href="http://www.martinfowler.com/eaaCatalog/activeRecord.html">Active Record pattern</a>.
<br \><br \>
Doctrine auto-creates database tables and always adds a primary key column named 'id' to tables. Only thing you need to for creating database tables
Doctrine auto-creates database tables and always adds a primary key column named 'id' to tables that doesn't have any primary keys specified. Only thing you need to for creating database tables
is defining a class which extends Doctrine_Record and setting a setTableDefinition method with hasColumn() method calls.
<br \><br \>
Consider we want to create a database table called 'user' with columns id(primary key), name, username, password and created. You only need couple of lines of code
to create a simple CRUD (Create, Retrieve, Update, Delete) application for this database table.
to create a simple up-and-running model.
......@@ -88,7 +88,14 @@ $menu = array("Getting started" =>
"Introduction",
"Data types and lengths",
"Constraints and validators",
"Enum emulation"
),
"Record identifiers" => array(
"Introduction",
"Autoincremented",
"Natural",
"Composite",
"Sequential")
),
"Basic Components" =>
array(
......
......@@ -472,7 +472,7 @@ class PHP_Highlight
case T_COMMENT:
case T_DOC_COMMENT:
case T_ML_COMMENT:
//case T_ML_COMMENT:
return $this->highlight['comment'];
break;
......
......@@ -13,7 +13,10 @@
<table width="100%" cellspacing=0 cellpadding=0>
<tr>
<td align="right">
<a href="index.php">main</a> | <a href="documentation.php">documentation</a> | <a href="https://sourceforge.net/project/showfiles.php?group_id=160015">download</a> | <a href="faq.php">FAQ</a> | <a href="about.php">about</a> | <a href="http://www.phpbbserver.com/phpdoctrine/">forums</a>
<?php
// https://sourceforge.net/project/showfiles.php?group_id=160015
?>
<a href="index.php">main</a> | <a href="documentation.php">documentation</a> | <a href="download.php">download</a> | <a href="faq.php">FAQ</a> | <a href="about.php">about</a> | <a href="http://www.phpbbserver.com/phpdoctrine/">forums</a>
</td>
<td width=30>
</td>
......
......@@ -61,10 +61,10 @@ class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase {
$query->addComponent("entity", "Entity");
$query->addComponent("phonenumber", "Entity.Phonenumber");
$coll = $query->execute();
$this->assertEqual($coll->count(), 11);
$count = $this->dbh->count();
$coll[4]->Phonenumber[0]->phonenumber;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment