summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxue <>2007-04-06 12:52:54 +0000
committerxue <>2007-04-06 12:52:54 +0000
commitd0bdd3144dfc972450d79ddaf6197a30b27eacc0 (patch)
treecb89b3a0be407d38300821d4ba3edd6ee73bb44d
parent34772099513df0734d3149e7b6d2d011f1f5e5e7 (diff)
Fixed some issues in day 2.
-rw-r--r--demos/blog-tutorial/protected/pages/Day2/ConnectDB.page7
-rw-r--r--demos/blog-tutorial/protected/pages/Day2/CreateAR.page55
-rw-r--r--demos/blog-tutorial/samples/day2/blog/protected/application.xml8
-rw-r--r--demos/blog-tutorial/samples/day2/blog/protected/database/PostRecord.php2
-rw-r--r--demos/blog-tutorial/samples/day2/blog/protected/database/UserRecord.php2
-rw-r--r--framework/TApplication.php8
6 files changed, 60 insertions, 22 deletions
diff --git a/demos/blog-tutorial/protected/pages/Day2/ConnectDB.page b/demos/blog-tutorial/protected/pages/Day2/ConnectDB.page
index 90db11ef..1d036577 100644
--- a/demos/blog-tutorial/protected/pages/Day2/ConnectDB.page
+++ b/demos/blog-tutorial/protected/pages/Day2/ConnectDB.page
@@ -28,18 +28,19 @@ We modify our application configuration file <tt>protected/application.xml</tt>
<com:TTextHighlighter CssClass="source" Language="xml">
<modules>
- <module class="System.Data.ActiveRecord.TActiveRecordConfig">
+ <module id="db" class="System.Data.TDataSourceConfig">
<database ConnectionString="sqlite:protected/data/blog.db" />
</module>
+ <module class="System.Data.ActiveRecord.TActiveRecordConfig" ConnectionID="db" />
</modules>
</com:TTextHighlighter>
<p>
-The configuration above shows that we are adding to our application a <a href="http://www.pradosoft.com/demos/quickstart/?page=Fundamentals.Modules">module</a> whose class is specified in the <a href="http://www.pradosoft.com/demos/quickstart/?page=Fundamentals.Components">namespace</a> format as <tt>System.Data.ActiveRecord.TActiveRecordConfig</tt>. Through this module, Active Record will automatically establish a DB connection by using the connection information given in <tt>ConnectionString</tt>.
+The configuration above shows that we are adding two <a href="http://www.pradosoft.com/demos/quickstart/?page=Fundamentals.Modules">modules</a> to our application. The <tt>TDataSourceConfig</tt> module is configured with the connection string <tt>sqlite:protected/data/blog.db</tt> which points to our SQLite database. This connection is used by the <tt>TActiveRecordConfig</tt> module which is required by Active Record.
</p>
<com:InfoBox>
-One may set up two or more DB connections in the application configuration. For more details, see the <a href="http://www.pradosoft.com/demos/quickstart/?page=Database.ActiveRecord">Active Record Documentation</a>. And of course, one may also explicitly create a DB connection in PHP code using the <a href="http://www.pradosoft.com/demos/quickstart/?page=Database.DAO">TDbConnection</a> component in PDO.
+One may set up two or more DB connections in the application configuration. For more details, see the <a href="http://www.pradosoft.com/demos/quickstart/?page=Database.ActiveRecord">Active Record documentation</a>. And of course, one may also explicitly create a DB connection in PHP code using the <a href="http://www.pradosoft.com/demos/quickstart/?page=Database.DAO">TDbConnection</a> component in PDO.
</com:InfoBox>
</com:TContent> \ No newline at end of file
diff --git a/demos/blog-tutorial/protected/pages/Day2/CreateAR.page b/demos/blog-tutorial/protected/pages/Day2/CreateAR.page
index bf2c05aa..d8b8b8ce 100644
--- a/demos/blog-tutorial/protected/pages/Day2/CreateAR.page
+++ b/demos/blog-tutorial/protected/pages/Day2/CreateAR.page
@@ -3,10 +3,20 @@
<h1>Creating Active Record Classes</h1>
<p>
-We need to create two <a href="http://www.pradosoft.com/demos/quickstart/?page=Database.ActiveRecord">Active Record</a> classes, <tt>UserRecord</tt> and <tt>PostRecord</tt>, to represent data records in the <tt>users</tt> and <tt>posts</tt> tables, respectively. Active Record classes must extend from the base class <tt>ActiveRecord</tt>, and their properties must match exactly to the fields of the corresponding tables. To better organize our directories, we create a new directory <tt>protected/database</tt> to hold the class files.
+We need to create two <a href="http://www.pradosoft.com/demos/quickstart/?page=Database.ActiveRecord">Active Record</a> classes, <tt>UserRecord</tt> and <tt>PostRecord</tt>, to represent data records in the <tt>users</tt> and <tt>posts</tt> tables, respectively. Active Record classes must extend from the base class <tt>ActiveRecord</tt>, and their properties must match exactly to the fields of the corresponding tables.
</p>
<p>
+To better organize our directories, we create a new directory <tt>protected/database</tt> to hold the class files. We also modify our application configuration by inserting the following lines. It is equivalent to adding the directory <tt>protected/database</tt> to PHP include_path, which allows us to use the classes without explicitly including them.
+</p>
+
+<com:TTextHighlighter CssClass="source" Language="xml">
+ <paths>
+ <using namespace="Application.database.*" />
+ </paths>
+</com:TTextHighlighter>
+
+<p>
Instead of writing the classes manually, we will use the <a href="http://www.pradosoft.com/demos/quickstart/?page=GettingStarted.CommandLine">PRADO command line tool</a> again to generate the classes for us.
</p>
@@ -54,19 +64,18 @@ We should see the following directory structure with two new files under <tt>pro
<img src="<%~ directories2.gif %>" />
<p>
-If we check the <tt>UserRecord</tt> class file, we should see the following content. As we see, for each field in the <tt>users</tt> table, the class has a corresponding data member. The constant <tt>TABLE</tt> specifies the table name for the <tt>UserRecord</tt>. The static method <tt>finder()</tt> allows us to perform query and retrieve users data in terms of <tt>UserRecord</tt> objects, as we will see in later sections.
+If we check the <tt>PostRecord</tt> class file, we should see the following content.
</p>
<com:TTextHighlighter CssClass="source" Language="php">
-class UserRecord extends TActiveRecord
+class PostRecord extends TActiveRecord
{
- const TABLE='users';
- public $username;
- public $email;
- public $password;
- public $role;
- public $first_name;
- public $last_name;
+ const TABLE='posts';
+ public $post_id;
+ public $author;
+ public $create_time;
+ public $title;
+ public $content;
public static function finder($className=__CLASS__)
{
@@ -75,4 +84,30 @@ class UserRecord extends TActiveRecord
}
</com:TTextHighlighter>
+<p>
+As we see, for each field in the <tt>posts</tt> table, the class has a corresponding data member. The constant <tt>TABLE</tt> specifies the table name for the <tt>PostRecord</tt>. The static method <tt>finder()</tt> allows us to perform query and retrieve post data in terms of <tt>PostRecord</tt> objects.
+</p>
+
+<p>
+We can use the command line tool to do some testing with our newly created Active Record classes. Still in the interactive mode of the command line tool, we enter a PHP statement and should see the following. Interested readers may try some other PHP statements, such as <tt>UserRecord::finder()->findAll()</tt>.
+</p>
+
+<com:TTextHighlighter CssClass="source" Language="text">
+>> PostRecord::finder()->findAll()
+array
+(
+ [0] => PostRecord#1
+ (
+ [post_id] => '1'
+ [author] => 'admin'
+ [create_time] => '1175708482'
+ [title] => 'first post'
+ [content] => 'this is my first post'
+ [TActiveRecord:_readOnly] => false
+ [TActiveRecord:_connection] => null
+ [TComponent:_e] => array()
+ )
+)
+</com:TTextHighlighter>
+
</com:TContent> \ No newline at end of file
diff --git a/demos/blog-tutorial/samples/day2/blog/protected/application.xml b/demos/blog-tutorial/samples/day2/blog/protected/application.xml
index 69cdbf9f..503b625a 100644
--- a/demos/blog-tutorial/samples/day2/blog/protected/application.xml
+++ b/demos/blog-tutorial/samples/day2/blog/protected/application.xml
@@ -1,12 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<application id="blog" mode="Debug">
- <!-- alias definitions and namespace usings
<paths>
- <alias id="myalias" path="./lib" />
- <using namespace="Application.common.*" />
+ <using namespace="Application.database.*" />
</paths>
- -->
<!-- configurations for modules -->
<modules>
@@ -23,9 +20,10 @@
<route class="TBrowserLogRoute" Categories="System" />
</module>
-->
- <module id="data" class="System.Data.ActiveRecord.TActiveRecordConfig">
+ <module id="db" class="System.Data.TDataSourceConfig">
<database ConnectionString="sqlite:protected/data/blog.db" />
</module>
+ <module class="System.Data.ActiveRecord.TActiveRecordConfig" ConnectionID="db" />
</modules>
<!-- configuration for available services -->
diff --git a/demos/blog-tutorial/samples/day2/blog/protected/database/PostRecord.php b/demos/blog-tutorial/samples/day2/blog/protected/database/PostRecord.php
index a9fb5db3..31451b30 100644
--- a/demos/blog-tutorial/samples/day2/blog/protected/database/PostRecord.php
+++ b/demos/blog-tutorial/samples/day2/blog/protected/database/PostRecord.php
@@ -1,6 +1,6 @@
<?php
/**
- * Auto generated by prado-cli.php on 2007-04-05 10:25:19.
+ * Auto generated by prado-cli.php on 2007-04-06 08:42:12.
*/
class PostRecord extends TActiveRecord
{
diff --git a/demos/blog-tutorial/samples/day2/blog/protected/database/UserRecord.php b/demos/blog-tutorial/samples/day2/blog/protected/database/UserRecord.php
index 5f2be169..2f657cd8 100644
--- a/demos/blog-tutorial/samples/day2/blog/protected/database/UserRecord.php
+++ b/demos/blog-tutorial/samples/day2/blog/protected/database/UserRecord.php
@@ -1,6 +1,6 @@
<?php
/**
- * Auto generated by prado-cli.php on 2007-04-05 10:23:57.
+ * Auto generated by prado-cli.php on 2007-04-06 08:42:08.
*/
class UserRecord extends TActiveRecord
{
diff --git a/framework/TApplication.php b/framework/TApplication.php
index 0d3d349a..c06bd080 100644
--- a/framework/TApplication.php
+++ b/framework/TApplication.php
@@ -866,8 +866,12 @@ class TApplication extends TComponent
Prado::trace("Loading module $id ({$moduleConfig[0]})",'System.TApplication');
list($moduleClass, $initProperties, $configElement)=$moduleConfig;
$module=Prado::createComponent($moduleClass);
- if(is_string($id))
- $this->setModule($id,$module);
+ if(!is_string($id))
+ {
+ $id='_module'.count($this->_modules);
+ $initProperties['id']=$id;
+ }
+ $this->setModule($id,$module);
foreach($initProperties as $name=>$value)
$module->setSubProperty($name,$value);
$modules[]=array($module,$configElement);