From eab6bb13b9efb3e1c6d725368368de4d74b00946 Mon Sep 17 00:00:00 2001 From: wei <> Date: Mon, 7 May 2007 04:17:37 +0000 Subject: Update Active Record docs. --- .gitattributes | 1 + UPGRADE | 3 + build.xml | 12 +- buildscripts/chmbuilder/ChmQuickstartBuilder.php | 16 +- buildscripts/chmbuilder/build.php | 2 +- buildscripts/chmbuilder/chm_style.css | 18 + buildscripts/phing/tasks/PradoQuickStartDocs.php | 85 +++ buildscripts/texbuilder/Page2Tex.php | 4 +- buildscripts/texbuilder/quickstart/build.php | 2 +- .../protected/pages/Advanced/Performance.page | 2 +- .../protected/pages/Advanced/Scripts3.page | 4 +- .../protected/pages/Configurations/Templates1.page | 2 +- .../protected/pages/Controls/Validation.page | 4 +- .../protected/pages/Database/ActiveRecord.page | 592 ++++++++++++++++++--- .../protected/pages/Database/Scaffold.page | 46 +- .../protected/pages/GettingStarted/AboutPrado.page | 4 +- .../pages/GettingStarted/Introduction.page | 12 +- .../pages/GettingStarted/NewFeatures.page | 6 +- .../protected/pages/Services/SoapService.page | 2 +- .../protected/pages/Tutorial/AddressBook.page | 4 +- demos/quickstart/themes/PradoSoft/style.css | 6 +- .../Relations/TActiveRecordBelongsTo.php | 2 +- .../Relations/TActiveRecordHasManyAssociation.php | 18 +- .../Relations/TActiveRecordRelation.php | 4 - .../Relations/TActiveRecordRelationContext.php | 13 +- framework/Data/ActiveRecord/TActiveRecord.php | 30 +- .../Data/ActiveRecord/TActiveRecordGateway.php | 13 +- framework/Data/Common/Sqlite/TSqliteMetaData.php | 5 +- framework/Data/DataGateway/TDataGatewayCommand.php | 13 +- framework/Data/DataGateway/TTableGateway.php | 27 +- .../simple_unit/ActiveRecord/FindBySqlTestCase.php | 29 +- .../ActiveRecord/ForeignObjectUpdateTest.php | 32 +- tests/simple_unit/DbCommon/SqliteColumnTest.php | 7 +- .../TableGateway/TableGatewayPgsqlTest.php | 2 +- 34 files changed, 856 insertions(+), 166 deletions(-) create mode 100644 buildscripts/phing/tasks/PradoQuickStartDocs.php diff --git a/.gitattributes b/.gitattributes index 333c1d80..a007f8b1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -617,6 +617,7 @@ buildscripts/phing/tasks/PhpLintTask.php -text buildscripts/phing/tasks/PradoDocTask.php -text buildscripts/phing/tasks/PradoPackageTask.php -text buildscripts/phing/tasks/PradoPearTask.php -text +buildscripts/phing/tasks/PradoQuickStartDocs.php -text buildscripts/phing/tasks/PradoTestTask.php -text buildscripts/phing/tasks/PradoVersionTask.php -text buildscripts/phing/tasks/QuickstartIndexTask.php -text diff --git a/UPGRADE b/UPGRADE index f18cb74f..b8076554 100644 --- a/UPGRADE +++ b/UPGRADE @@ -17,7 +17,10 @@ Upgrading from v3.1b - Comment tag (introduced in v3.1a) is changed to - When TDataList.RepeatLayout is Raw, the items will render
instead of + - TActiveRecord finder methods will always return a new object instance (identity mapping was removed). +- TActiveRecord::findBySql() will return an object rather than an array +- TActiveRecord::findAllBySql() will return an array of objects. Upgrading from v3.1a --------------------- diff --git a/build.xml b/build.xml index 96f3c251..88be065f 100644 --- a/build.xml +++ b/build.xml @@ -14,6 +14,7 @@ + @@ -149,11 +150,12 @@ - snapshot: generate nightly snapshot; - + + @@ -163,8 +165,11 @@ - + + @@ -174,6 +179,7 @@ + @@ -223,6 +229,7 @@ + @@ -237,6 +244,7 @@ + diff --git a/buildscripts/chmbuilder/ChmQuickstartBuilder.php b/buildscripts/chmbuilder/ChmQuickstartBuilder.php index 678310a6..43b55d12 100644 --- a/buildscripts/chmbuilder/ChmQuickstartBuilder.php +++ b/buildscripts/chmbuilder/ChmQuickstartBuilder.php @@ -13,12 +13,12 @@ class ChmQuickstartBuilder public function __construct($base,$output) { $this->base = $base; - $this->output_dir = $output.'/quickstart'; + $this->output_dir = $output; - if(!is_dir($this->output_dir)) + if(!is_dir($this->output_dir) || !is_dir($this->output_dir.'/assets')) { - mkdir($this->output_dir); - mkdir($this->output_dir.'/assets/'); + @mkdir($this->output_dir); + @mkdir($this->output_dir.'/assets/'); copy(dirname(__FILE__).'/chm_style.css', $this->output_dir.'/assets/chm_style.css'); } @@ -58,7 +58,7 @@ class ChmQuickstartBuilder file_put_contents($this->output_dir.'/'.$file, $html); } - protected function getApplicationContent() + public function getApplicationContent() { ob_start(); $this->initApp(); @@ -68,7 +68,7 @@ class ChmQuickstartBuilder return $content; } - protected function parseHtmlContent($content) + public function parseHtmlContent($content) { $html = preg_replace('/]+\/>/m', '', $content); $html = str_replace('

To update a record in the database, just change one or more properties of @@ -341,7 +408,7 @@ $user->save(); //update it.

-

+

Active Record objects have a simple life-cycle illustrated in the following diagram.

alt="Active Records Life Cycle" id="fig:cycle.png" class="figure"/> @@ -350,43 +417,43 @@ We see that new TActiveRecord objects are created by either using one of the new keyword. Objects created by a find*() method starts with clean state. New instance of TActiveRecord created other than by a find*() method starts with new state. -When ever you +Whenever you call the save() method on the TActiveRecord object, the object enters the clean state. Objects in the clean becomes dirty whenever one of more of its internal states are changed. Calling the delete() method on the object -ends the object life-cycle, no futher actions can be performed on the object. +ends the object life-cycle, no further actions can be performed on the object.

Deleting existing records

To delete an existing record that is already loaded, just call the delete() method. You can also delete records in the database by primary keys without - loading any records using the deleteByPk() method. - For example, to delete one or records with tables having a scalar primary key. + loading any records using the deleteByPk() method (and equivalently the deleteAllByPks() method). + For example, to delete one or records with tables using one or more primary keys.

$finder->deleteByPk($primaryKey); //delete 1 record -$finder->deleteByPk($key1,$key2,...); //delete multiple records -$finder->deleteByPk(array($key1,$key2,...)); //delete multiple records +$finder->deleteAllByPks($key1,$key2,...); //delete multiple records +$finder->deleteAllByPks(array($key1,$key2,...)); //delete multiple records

-For composite primary keys (determined automatically from the table definitions): +For composite keys (determined automatically from the table definitions):

$finder->deleteByPk(array($key1,$key2)); //delete 1 record //delete multiple records -$finder->deleteByPk(array($key1,$key2), array($key3,$key4),...); +$finder->deleteAllByPks(array($key1,$key2), array($key3,$key4),...); //delete multiple records -$finder->deleteByPk(array( array($key1,$key2), array($key3,$key4), .. )); +$finder->deleteAllByPks(array( array($key1,$key2), array($key3,$key4), .. ));

deleteAll() and deleteBy*()

To delete by a criteria, use deleteAll($criteria) and deleteBy*() -with similar synatx to findAll($criteria) and findAllBy*() as +with similar syntax to findAll($criteria) and findAllBy*() as described above.

@@ -399,7 +466,7 @@ $finder->deleteBy_Username_And_Password($name,$pass);

Transactions

-

All Active Record objects contains the property DbConnection +

All Active Record objects contain the property DbConnection that can be used to obtain a transaction object. $finder = UserRecord::finder(); @@ -418,25 +485,76 @@ catch(Exception $e) // an exception is raised if a query fails } +

Events

+

+The TActiveRecord offers two events, OnCreateCommand and OnExecuteCommand. +

+ +

The OnCreateCommand event is raised when a command is prepared and +parameter binding is completed. The parameter object is TDataGatewayEventParameter of which the +Command property can be inspected to obtain the SQL query to be executed. +

+ +

+The OnExecuteCommand event is raised when a command is executed and the +result from the database was returned. The parameter object is TDataGatewayResultEventParameter +of which the Result property contains the data return from the database. +The data returned can be changed by setting the Result property. +

+ +

Logging Example

+

Using the OnExecuteCommand we can attach an event handler to log +the entire SQL query executed for a given TActiveRecord class or instance. For example, we define +a base class and override either the getDbConnection() or the constructor. +

+ + +class MyDb1Record extends TActiveRecord +{ + public function getDbConnection() + { + static $conn; + if($conn===null) + { + $conn = new TDbConnection('xxx','yyy','zzz'); + $this->OnExecuteCommand[] = array($this,'logger'); + } + return $conn; + } + public function logger($sender,$param) + { + var_dump($param->Command->Text); + } +} +//alternatively as per instance of per finder object +function logger($sender,$param) +{ + var_dump($param->Command->Text); +} +TActiveRecord::finder('MyRecord')->OnExecuteCommand[] = 'logger'; +$obj->OnExecuteCommand[] = array($logger, 'log'); //any valid PHP callback. + +

Active Record Relationships

+

The Prado Active Record implementation supports the foreign key mappings for database -that supports foreign key contraints. For ActiveRecord relationships to function the -underlying database must support foreign key constraints (e.g. MySQL with InnoDB). +that supports foreign key constraints. For Active Record relationships to function the +underlying database must support foreign key constraints (e.g. MySQL using InnoDB).

-

+

In the following sections we shall consider the following table relationships between Teams, Players, Skills and Profiles.

- + class="figure" /> -

The goal is to obtain object models that represents to some degree the entity +

The goal is to obtain object models that represent to some degree the entity relationships in the above figure.

- + class="figure" />

There is a mismatch between relationships with objects and table relationships. @@ -449,14 +567,33 @@ structure between objects and tables. The approach taken in the Prado Active Rec design is to use the table foreign key constraints to derive object relationships. This implies that the underlying database must support foreign key constraints.

-

Foreign Key Mapping

+
Tip: +For SQLite database, you may create tables that defines the foreign key +constraints such as the example below. However, these constraints are NOT +enforced by the SQLite database itself. + +CREATE TABLE foo +( + id INTEGER NOT NULL PRIMARY KEY, + id2 CHAR(2) +); +CREATE TABLE bar +( + id INTEGER NOT NULL PRIMARY KEY, + foo_id INTEGER + CONSTRAINT fk_foo_id REFERENCES foo(id) ON DELETE CASCADE +); + +
+ +

Foreign Key Mapping

The entity relationship between the Teams and Players table is what is known as an 1-M relationship. That is, one Team may contain 0 or more Players. In terms of -object relationships, we say that the Team object has many Player objects. +object relationships, we say that a TeamRecord object has many PlayerRecord objects. (Notice the reversal of the reversal of the direction of relationships between tables and objects.) -

-

Has Many Relationship

-

+

+

Has Many Relationship

+

We model the Team object as the following Active Record classes.

@@ -480,50 +617,50 @@ class TeamRecord extends TActiveRecord } } -

+

The static $RELATIONS property of TeamRecord defines that the -property $players has many PlayerRecords. Multiple relationships +property $players has many PlayerRecords. Multiple relationships is permitted by defining each relationship with an entry in the $RELATIONS array where array key for the entry corresponds to the property name. In array(self::HAS_MANY, 'PlayerRecord'), the first element defines the -relationship type, the valid types are self::HAS_MANY, -self::HAS_ONE and self::BELONGS_TO. +relationship type, the valid types are self::HAS_MANY, +self::HAS_ONE and self::BELONGS_TO. The second element is a string 'PlayerRecord' that corresponds to the class name of the PlayerRecord class.

-

+

The foreign key constraint of the Players table is used to determine the corresponding Teams table's corresponding key names. This is done automatically handled in Active Record by inspecting the Players and Teams table definitions.

Info: -Active Record supports multiple table foreign key relationships with the restiction -that each relationship correponds to a unique table. For example, the Players +Active Record supports multiple table foreign key relationships with the restriction +that each relationship corresponds to a unique table. For example, the Players table may only have one set of foreign key relationship with table Teams, it may have other relationships that corresponds to other tables (including the Players table itself).
-

The has many relationship is not fetched automatically when you use any of the Active Record finder methods. +

The "has many" relationship is not fetched automatically when you use any of the Active Record finder methods. You will need to explicitly fetch the related objects as follows. In the code below, both lines are equivalent and the method names are case insensitive.

$team = TeamRecord::finder()->withPlayers()->findAll(); $team = TeamRecord::finder()->with_players()->findAll(); //equivalent - -

+ +

The method with_xxx() (where xxx is the relationship property -name, in this case, players) fetchs the corresponding PlayerRecords using +name, in this case, players) fetches the corresponding PlayerRecords using a second query (not by using a join). The with_xxx() accepts the same -arguments as other finder methods of TActiveRecord, e.g. with_players('age < ?', 35). +arguments as other finder methods of TActiveRecord, e.g. with_players('age = ?', 35).

Note: It is essential to understand that the related objects are fetched using additional -queries. The first query fetches the source object, .e.g the TeamRecord in the above example code. -A second query is used to fetche the corresponding related PlayerRecord objects. +queries. The first query fetches the source object, e.g. the TeamRecord in the above example code. +A second query is used to fetch the corresponding related PlayerRecord objects. The usage of the two query is similar to a single query using Left-Outer join with the exception that null results on the right table are not returned. The consequence of using two or more queries is that the aggregates @@ -531,8 +668,15 @@ and other join conditions are not feasible using Active Records. For queries out scope of Active Record the SqlMap Data Mapper may be considered.
-

Belongs To Relationship

- +

Belongs To Relationship

+

The "has many" relationship in the above section defines a collection of foreign +objects. In particular, we have that a TeamRecord has many (zero or more) +PlayerRecord objects. We can also add a back pointer by adding a property +in the PlayerRecord class that links back to the TeamRecord object, +effectively making the association bidirectional. +We say that the $team property in PlayerRecord class belongs to a TeamRecord object. +The following code defines the complete PlayerRecord class with 3 relationships. +

class PlayerRecord extends TActiveRecord { @@ -558,9 +702,41 @@ class PlayerRecord extends TActiveRecord } } +

+The static $RELATIONS property of PlayerRecord defines that the +property $team belongs to a TeamRecord. +The $RELATIONS array also defines two other relationships that we +shall examine in later sections below. +In array(self::BELONGS_TO, 'TeamRecord'), the first element defines the +relationship type, in this case self::BELONGS_TO and +the second element is a string 'TeamRecord' that corresponds to the +class name of the TeamRecord class. +A player object with the corresponding team object may be fetched as follows. +

+ +$players = PlayerRecord::finder()->with_team()->findAll(); + + +

+ The method with_xxx() (where xxx is the relationship property + name, in this case, team) fetches the corresponding TeamRecords using + a second query (not by using a join). The with_xxx() accepts the same +arguments as other finder methods of TActiveRecord, e.g. +with_team('location = ?', 'Madrid'). +

-

Has One Relationship

+
Tip: +Additional relationships may be fetched by chaining the with_xxx() together as the following +example demonstrates. + +$players = PlayerRecord::finder()->with_team()->with_skills()->findAll(); + +Each with_xxx() method will execute an additional SQL query. Every +with_xxx() accepts arguments similar to those in the findAll() method and is only +applied to that particular relationship query. +
+

The "belongs to" relationship of ProfileRecord class is defined similarly.

class ProfileRecord extends TActiveRecord { @@ -582,8 +758,84 @@ class ProfileRecord extends TActiveRecord } +

In essence, there exists a "belongs to" relationship for objects corresponding to +entities that has column which are foreign keys. In particular, we see that +the Profiles table has a foreign key constraint on the column player_id +that relates to the Players table's player_id column. Thus, the ProfileRecord +object has a property ($player) that belongs to a PlayerRecord object. +Similarly, the Players table has a foreign key constraint on the column team_name that relates to the +Teams table's name column. +Thus, the PlayerRecord object has a property ($team) that belongs to a +TeamRecord object. +

+ +

Has One Relationship

+

The entity relationship between Players and Profiles is one to one. That is, +each PlayerRecord object has one ProfileRecord object (may be none or null). +A has one relationship is nearly identical to a has many relationship with the exception +that the related object is only one object (not a collection of objects). +

+ +

Parent Child Relationships

+

A parent child relationship can be defined using a combination of has many and belongs to +relationship that refers to the same class. The following example shows a parent children relationship between +"categories" and a "parent category". +

+ + +class Category extends TActiveRecord +{ + public $cat_id; + public $category_name; + public $parent_cat_id; + + public $parent_category; + public $child_categories=array(); + + protected static $RELATIONS=array + ( + 'parent_category' => array(self::BELONGS_TO, 'Category'), + 'child_categories' => array(self::HAS_MANY, 'Category'), + ); +} + + -

Association Table Mapping

+

Association Table Mapping

+

+Objects can handle multivalued fields quite easily by using collections as field values. +Relational databases don't have this feature and are constrained to single-valued fields only. +When you're mapping a one-to-many association you can handle this using has many relationships, +essentially using a foreign key for the single-valued end of the association. +But a many-to-many association can't do this because there is no single-valued end to +hold the foreign key. +

+

+The answer is the classic resolution that's been used by relational data people +for decades: create an extra table (an association table) to record the relationship. +The basic idea is using an association table to store the association. This table +has only the foreign key IDs for the two tables that are linked together, it has one +row for each pair of associated objects. +

+

+The association table has no corresponding in-memory object and its primary key is the +compound of the two primary keys of the tables that are associated. +In simple terms, to load data from the association table you perform two queries (in general, it may also be achieved using one query consisting of joins). +Consider loading the SkillRecord collection for a list PlayerRecord objects. +In this case, you do queries in two stages. +The first stage queries the Players table to find all the rows of the players you want. +The second stage finds the SkillRecord object for the related player ID for each row +in the Player_Skills association table using an inner join. +

+ +

The Prado Active Record design implements the two stage approach. For the +Players-Skills M-N (many-to-many) entity relationship, we need +to define a has many relationship in the PlayerRecord class and +in addition define a has many relationship in the SkillRecord class as well. +The following sample code defines the complete SkillRecord class with a +many-to-many relationship with the PlayerRecord class. (See the PlayerRecord +class definition above to the corresponding many-to-many relationship with the SkillRecord class.) +

class SkillRecord extends TActiveRecord @@ -606,6 +858,186 @@ class SkillRecord extends TActiveRecord } +

+The static $RELATIONS property of SkillRecord defines that the +property $players has many PlayerRecords via an association table 'Player_Skills'. +In array(self::HAS_MANY, 'PlayerRecord', 'Player_Skills'), the first element defines the +relationship type, in this case self::HAS_MANY, +the second element is a string 'PlayerRecord' that corresponds to the +class name of the PlayerRecord class, and the third element is the name +of the association table name. +

+

+A list of player objects with the corresponding collection of skill objects may be fetched as follows. +

+ +$players = PlayerRecord::finder()->withSkills()->findAll(); + +

+The method with_xxx() (where xxx is the relationship property +name, in this case, Skill) fetches the corresponding SkillRecords using +a second query (not by using a join). The with_xxx() accepts the same +arguments as other finder methods of TActiveRecord. +

+ +

Self Referenced Association Tables

+

+For self referenced association tables, that is, the association points to the same +table. For example, consider the items table with M-N related +item via the related_items association table. The syntax in the following +example is valid for a PostgreSQL database. For other database, consult their respective documentation for +defining the foreign key constraints. + +CREATE TABLE items +( + "item_id" SERIAL, + "name" VARCHAR(128) NOT NULL, + PRIMARY KEY("item_id") +); +CREATE TABLE "related_items" +( + "item_id" INTEGER NOT NULL, + "related_item_id" INTEGER NOT NULL, + CONSTRAINT "related_items_pkey" PRIMARY KEY("item_id", "related_item_id"), + CONSTRAINT "related_items_item_id_fkey" FOREIGN KEY ("item_id") + REFERENCES "items"("item_id") + ON DELETE CASCADE + ON UPDATE NO ACTION + NOT DEFERRABLE, + CONSTRAINT "related_items_related_item_id_fkey" FOREIGN KEY ("related_item_id") + REFERENCES "items"("item_id") + ON DELETE CASCADE + ON UPDATE NO ACTION + NOT DEFERRABLE +); + + +

The association table name in third element of the relationship array may +contain the foreign table column names. The columns defined in the association +table must also be defined in the record class (e.g. the $related_item_id property +corresponds to the related_item_id column in the related_items table). +

+ +class Item extends TActiveRecord +{ + const TABLE="items"; + public $item_id; + public $details; + + //additional foreign item id defined in the association table + public $related_item_id; + public $related_items=array(); + + protected static $RELATIONS=array + ( + 'related_items' => array(self::HAS_MANY, + 'Item', 'related_items.related_item_id'), + ); +} + +
Tip: +Compound keys in the foreign table can +be specified as comma separated values between brackets. E.g. +'related_items.(id1,id2)'. +
+ +

Adding/Removing/Updating Related Objects

+ +

Related objects can be simply inserted/updated by first adding those related objects to +the current source object (i.e. the object currently been worked on) and then call +the save() method on the source object. The related object's references +and the association reference (if required) will be added and/or updated. +For example, to add two new players to the team (assuming that 'Team A' exists), we can simply do the following. +

+ + +$team = TeamRecord::finder()->findByPk('Team A'); +$team->players[] = new PlayerRecord(array('age'=>20)); +$team->players[] = new PlayerRecord(array('age'=>25)); +$team->save(); + +

+Since the TeamRecord class contains a has many relationship with the PlayerRecord, +then saving a TeamRecord object will also update the corresponding foreign objects in $players array. +That is, the objects in $players are inserted/updated in the database and the +$team_name property of those objects will contain the foreign key value that corresponds to the $team object's primary key value. +

+ +

To delete a particular foreign object (or any Active Record object), simply call +the object's delete() method. You may setup the database table's foreign key constraints such that +when deleting a particular data in the database it will delete the referenced data as well (it may also be achieved using database +triggers). E.g. such as having a "ON DELETE CASCADE" constraint. +Deleting foreign objects by either setting the property value to null or removing the object from an array will NOT +remove the corresponding data in the database. +

+ +

To remove associations for the many-to-many relationships via an association table, an Active Record +that corresponds to the association table can be used. Then the association can be removed by calling the deleteByPk() method, for example: +

+ +PlayerSkillAssocation::finder()->deleteByPk(array('fk1','fk2')); +//where 'fk1' is the primary key value of a player +// and 'fk2' is the primary key value of a skill + + +

Lazy Loading Related Objects

+

Using the with_xxx() methods will load the relationship record on demand. Retrieving the +related record using lazy loading (that is, only when those related objects are accessed) can be +achieved by using a feature of the TComponent that provides accessor methods. In particular, +we define a pair of getter and setter methods where the getter method will retrieve the relationship +conditionally. The following example illustrates that the PlayerRecord can retrieve its +$skills foreign objects conditionally. +

+ +class PlayerRecord extends BaseFkRecord +{ + //... other properties and methods as before + + private $_skills; //change to private and default as null + + public function getSkills() + { + if($this->_skills===null && $this->player_id !==null) + { + //lazy load the skill records + $this->setSkills($this->withSkills()->findByPk($this->player_id)->skills); + } + else if($this->_skills===null) + { + //create new TList; + $this->setSkills(new TList()); + } + + return $this->_skills; + } + + public function setSkills($value) + { + $this->_skills = $value instanceof TList ? $value : new TList($value); + } +} + +

We first need to change the $skills=array() declaration to a private property +$_skills (notice the underscore) and set it to null instead. This allows us +to define the skills property using getter/setter methods +(see Components for details). The getSkills() +getter method for the skills property will lazy load the corresponding skills foreign record +when it is used as follows. Notice that we only do a lazy load when its $player_id is +not null (that is, when the record is already fetched from the database or player id was already set). +

+ +$player = PlayerRecord::finder()->findByPk(1); +var_dump($player->skills); //lazy load it on first access +var_dump($player->skills[0]); //already loaded skills property +$player->skills[] = new SkillRecord(); //add skill + + +

The setSkills() ensures that the skills property will always be a TList. +Using a TList allows us to set the elements of the skills property as if they were +arrays. E.g. $player->skills[] = new SkillRecord(). If array was used, a PHP error +will be thrown. +

+

References

  • Fowler et. al. Patterns of Enterprise Application Architecture, diff --git a/demos/quickstart/protected/pages/Database/Scaffold.page b/demos/quickstart/protected/pages/Database/Scaffold.page index 9afe4a3f..759e55d1 100644 --- a/demos/quickstart/protected/pages/Database/Scaffold.page +++ b/demos/quickstart/protected/pages/Database/Scaffold.page @@ -1,8 +1,8 @@ -

    Active Record Scaffold Views

    +

    Active Record Scaffold Views

    -

    Active Record classes can be used together with +

    Active Record classes can be used together with and @@ -10,7 +10,7 @@ and links both TScaffoldListView and TScaffoldEditView) to create simple Create/Read/Update/Delete (CRUD) web applications.

    -

    The scaffold views are intended to assist in prototyping web application, +

    The scaffold views are intended to assist in prototyping web application, they are not designed to be as customiziable as more complex components such as TDataGrid. The scaffold views provide the following builtin functionality: @@ -27,18 +27,18 @@ the following builtin functionality:

  • Presents specialized controls such as date pickers.
-

Scaffold views are dependent on Active Records and currently supports +

Scaffold views are dependent on Active Records and currently supports the following databases: Mysql, Sqlite and Postgres SQL. Support for other databases can be considered when there are sufficient demand.

-

Setting up a Scaffold View

-

To use the scaffold view, we first define an Active Record +

Setting up a Scaffold View

+

To use the scaffold view, we first define an Active Record class that represents a table or view in the database. Consider the following Active Record class that corresponds to the users table as defined in the Active Record quickstart page.

- + class UserRecord extends TActiveRecord { const TABLE='users'; @@ -48,7 +48,7 @@ class UserRecord extends TActiveRecord } -

The scaffold view classes are in the System.Data.ActiveRecord.Scaffold.* +

The scaffold view classes are in the System.Data.ActiveRecord.Scaffold.* namespace. This namespace can be "imported" in the Application Configuration @@ -59,11 +59,11 @@ simply set the RecordClass property value equal to an Active Record class name.

- + <com:TScaffoldView RecordClass="UserRecord" /> -

The above code will list the current records in the users table. +

The above code will list the current records in the users table. Each record can be edited by clicking on the "edit" button and deleted by clicking on the "delete" button. A new record can be added by clicking on the "Add new record" button, enter some data (notice the automatic validation of required fields and data types), and click the "save" button. @@ -71,20 +71,20 @@ Specifying search terms in the search textbox to find particular records. Finall record list can be sorted for each column by changing the sorting column and order.

-

The TScaffoldView is a template control composed of other scaffold controls. +

The TScaffoldView is a template control composed of other scaffold controls. The following properties gives access to these composite controls.

  • ListView -- the TScaffoldListView displaying the record list.
  • EditView -- the TScaffoldEditView that renders the inputs for editing and adding records.
  • SearchControl -- the TScaffoldSearch responsible to the search user interface.
-

+

All these composite controls can be customized as we shall see below.

-

TScaffoldListView

+

TScaffoldListView

-

A list of Active Records can be displayed using the TScaffoldListView +

A list of Active Records can be displayed using the TScaffoldListView with the following useful properties.

  • Header -- a TRepeater @@ -96,7 +96,7 @@ the links and/or buttons that navigate to different pages in the Active Record d
  • List -- a TRepeater that renders a row of Active Record data.
-

Custom rendering of the each Active Record can be achieved by specifying +

Custom rendering of the each Active Record can be achieved by specifying the ItemTemplate and/or AlternatingItemTemplate property of the List repeater. The TScaffoldListView will listen for two command events named "delete" and @@ -106,7 +106,7 @@ An "edit" command will push the record data to be edited by a The following example lists the usernames only with bold formatting.

- + <com:TScaffoldListView RecordClass="UserRecord" > <prop:List.ItemTemplate> <strong><%# $this->Data->username %></strong> @@ -120,27 +120,27 @@ Thus, the subproperty ListView.List.ItemTemplate on TScaffoldViewList.ItemTemplate subproperty of TScaffoldListView in the above example.
-

The SearchCondition property and +

The SearchCondition property and SearchParameters property (takes array values) can be specified to customize the records to be shown. The SearchCondition will be used as the Condition property of TActiveRecordCriteria and the SearchParameters property corresponds to Parameters property of TActiveRecordCriteria.

-

TScaffoldEditView

- +

TScaffoldEditView

+ <com:TScaffoldEditView RecordPk="user1" RecordClass="UserRecord" /> -

Combining list + edit views

+

Combining list + edit views

- + <com:TScaffoldEditView ID="edit_view" RecordClass="UserRecord" /> <com:TScaffoldListView EditViewID="edit_view" RecordClass="UserRecord" /> -

Customizing the TScaffoldView

- +

Customizing the TScaffoldView

+ <com:TScaffoldView RecordClass="UserRecord" > <prop:ListView.List.ItemTemplate> <%# $this->DataItem->username %> diff --git a/demos/quickstart/protected/pages/GettingStarted/AboutPrado.page b/demos/quickstart/protected/pages/GettingStarted/AboutPrado.page index 1d40a8d9..42e4346f 100644 --- a/demos/quickstart/protected/pages/GettingStarted/AboutPrado.page +++ b/demos/quickstart/protected/pages/GettingStarted/AboutPrado.page @@ -49,8 +49,8 @@ PRADO is often quoted as a unique framework. Its uniqueness mainly lies in the c Most PHP frameworks mainly focuses on separating presentation and logic and promotes the MVC (model-view-controller) design pattern. PRADO achieves the same goal naturally by requiring logic be stored in classes and presentation in templates. PRADO does much more on aspects other than MVC. It fills lot of blank area in PHP Web programming with its component-based programming paradigm, its rich set of Web controls, its powerful database support, its flexible error handling and logging feature, and many others.

-

Is PRADO Stable Enough?

-

+

Is PRADO Stable Enough?

+

Yes. PRADO was initially released in August 2004. Many test suites have been written and conducted frequently to ensure its quality. It has been used by thousands of developers and many Web applications have been developed based on it. Bugs and feature requests are managed through TRAC system and we have a great user community and development team to ensure all questions are answered in a timely fashion.

diff --git a/demos/quickstart/protected/pages/GettingStarted/Introduction.page b/demos/quickstart/protected/pages/GettingStarted/Introduction.page index f267d23d..3fd67d5d 100644 --- a/demos/quickstart/protected/pages/GettingStarted/Introduction.page +++ b/demos/quickstart/protected/pages/GettingStarted/Introduction.page @@ -4,14 +4,14 @@

This Quickstart tutorial is provided to help you quickly start building your own Web applications based on PRADO version 3.x.

-

+

If you are an existing PRADO 3.x user and would like to learn what enhancements are available for each new version, please check out the new features page. Otherwise, the following sections are helpful for newbies.