Skip to content

Commit

Permalink
merge from 1.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
qiang.xue committed May 10, 2009
1 parent 8efec6a commit 3aa81fa
Show file tree
Hide file tree
Showing 25 changed files with 667 additions and 243 deletions.
13 changes: 11 additions & 2 deletions CHANGELOG
Expand Up @@ -8,26 +8,33 @@ Version 1.1a to be released
Version 1.0.5 to be released
----------------------------
- Bug #234: Multi-line Yii::t() not found by 'yiic message' (Qiang)
- Bug #235: Dynamic content does not work when page caching is used together with fragment caching (Qiang)
- Bug #239: Syntax error in translated Portuguese error view file (Qiang)
- Bug #246: Undefined variable in CMaskedTextField (Qiang)
- Bug #252: mimeTypes.php contains clashing types (Qiang)
- Bug #258: Some eager loading queries may result in extra lazy loading queries (Qiang)
- Bug #261: CWsdlGenerator should not use 'tns:' namespace when declaring a complex type (Qiang)
- Bug #262: Setting 'charset' of CDbConnection causes exception when working with SQLite (Qiang)
- Bug #263: Exception is thrown when column names contain "=" symbol (Qiang)
- Bug #270: CComponent::detachBehavior() uses undefined index (Qiang)
- Bug #290: date formatter generates incorrect narrow day output (Qiang)
- Bug: Lazy loading HAS_MANY or MANY_MANY properties will get NULL instead of empty array when the result set is empty (Qiang)
- Bug: CDateFormatter::formatYear() only returns one digit when the year pattern is 'yy' (Qiang)
- Bug: The ON option is not respected for MANY_MANY relations (Qiang)
- New #210: Added support for named scope of AR (Qiang)
- New #211: Enhanced AR by supporting lazy relational query with on-the-fly query parameters (Qiang)
- New #224: Added CModel::addErrors() method (Qiang)
- New #241: Added support to define root path aliases in configuration (Qiang)
- New #247: Added support to allow using Web services in PHP versions lower than 5.2.0 (Qiang)
- New #249: Added option to CHtml to allow generate tags without encoding attribute values (Qiang)
- New #254: Added support to allow input widgets to be used with tabular inputs (Qiang)
- New #265: Added support to validate time and datetime inputs (Qiang)
- New #268: Added support to allow using dot syntax to generate list options with CHtml (Qiang)
- New #274: Added support to allow using route sub-patterns in URL rules (Qiang)
- New #284: Refactored code about page states to simplify overriding efforts (Qiang)
- New #291: Added support to validate emails with name part (Qiang)
- New #293: Added support to allow Yii to be used with other libraries which rely on autoload (Qiang)
- New #294: Added CDummyCache component (Qiang)
- New: Deprecated CHtml::getActiveId() (Qiang)
- New: Added CDbCriteria::mergeWith() (Qiang)
- New: Added Oracle support for Active Record (Ricardo)
Expand All @@ -39,7 +46,8 @@ Version 1.0.5 to be released
- New: Added new message placeholder to CCompareValidator (Qiang)
- New: Added trace statements to auth components (Qiang)
- New: Added CHtml::value() (Qiang)

- New: Enhanced 'yiic shell model' command so that it generates attribute labels by default (Qiang)
- New: Added CDbConnection::enableParamLogging to allow logging parameters bound to SQL statements (Qiang)

Version 1.0.4 April 5, 2009
---------------------------
Expand Down Expand Up @@ -79,7 +87,8 @@ Version 1.0.4 April 5, 2009
- New #212: 'Readline' support in yiic console script (olafure)
- New #225: Added trace statements to CActiveRecord and CActiveFinder (Qiang)
- New #230: Enhanced CHtml so that it can be used in situations where controller is absent (Qiang)
- New #233: allow CFileValidator::types to be set with an array (Qiang)
- New #233: Allow CFileValidator::types to be set with an array (Qiang)
- New #292: Refactored CActiveRecord so that attribute assignment can be overridden more easily (Qiang)
- New: Added support to GROUP BY and HAVING in eager loading of AR (Qiang)
- New: Added CClientScript::scriptFiles and CClientScript::cssFiles (Qiang)
- New: Added SQL Server support for Active Record (Christophe)
Expand Down
8 changes: 8 additions & 0 deletions docs/guide/caching.overview.txt
Expand Up @@ -50,6 +50,14 @@ it will create and use a SQLite3 database under the runtime directory. You
can explicitly specify a database for it to use by setting its
[connectionID|CDbCache::connectionID] property.

- [CDummyCache]: presents dummy cache that does no caching at all. The purpose
of this component is to simplify the code that needs to check the availability of cache.
For example, during development or if the server doesn't have actual cache support, we
can use this cache component. When an actual cache support is enabled, we can switch
to use the corresponding cache component. In both cases, we can use the same code
`Yii::app()->cache->get($key)` to attempt retrieving a piece of data without worrying
that `Yii::app()->cache` might be `null`. This component has been available since version 1.0.5.

> Tip: Because all these cache components extend from the same base class
[CCache], one can switch to use a different type of cache without modifying
the code that uses cache.
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/caching.page.txt
Expand Up @@ -26,7 +26,7 @@ public function filters()
{
return array(
array(
'system.web.widgets.COutputCache',
'COutputCache',
'duration'=>100,
'varyByParam'=>array('id'),
),
Expand Down
4 changes: 4 additions & 0 deletions docs/guide/changes.txt
Expand Up @@ -8,10 +8,14 @@ Version 1.0.5

* Enhanced active record by supporting named scopes. See:
- [Named Scopes](/doc/guide/database.ar#named-scopes)
- {Default Named Scope](/doc/guide/database.ar#default-named-scope)
- [Relational Query with Named Scopes](/doc/guide/database.arr#relational-query-with-named-scopes)


* Enhanced active record by supporting lazy loading with dynamic query options. See:
- [Dynamic Relational Query Options](/doc/guide/database.arr#dynamic-relational-query-options)

* Enhanced [CUrlManager] to support parameterizing the route part in URL rules. See:
- [Parameterizing Routes in URL Rules](/doc/guide/topics.url#parameterizing-routes)

<div class="revision">$Id$</div>
30 changes: 21 additions & 9 deletions docs/guide/database.ar.txt
Expand Up @@ -43,6 +43,7 @@ used for modeling database tables in PHP constructs and performing queries
that do not involve complex SQLs. Yii DAO should be used for those complex
scenarios.


Establishing DB Connection
--------------------------

Expand Down Expand Up @@ -149,13 +150,15 @@ a column in the `Post` table, and CActiveRecord makes it accessible as a
property with the help of the PHP `__get()` magic method. An exception will
be thrown if we attempt to access a non-existing column in the same way.

> Info: For better readability, we suggest naming database tables and
columns in camel case. In particular, table names are formed by
capitalizing each word in the name and joining them without spaces; column
names are similar to table names except their first letter is in lower
case. For example, we use `Post` to name the table storing posts; and we
use `createTime` to name the table's primary key column. This makes tables
look more like class types and columns like variables. Note, however, using camel case may also bring you inconvenience for some DBMS, such as MySQL, as they may behave differently on different operation systems.
> Info: For better readability, we suggest naming table columns in camel case.
In particular, column names are formed by capitalizing each word except
the first one in the name and concatenating them without spaces. For example, we
may use `createTime` to name a column storing the creation time of a row.
Naming of tables depends on your personal taste. In this guide, we also follow
camel case naming convention except that the first letter is in upper case as well.
For example, we use `Post` to name the table storing post data.
Note, however, using camel case for table names may bring you inconvenience
for some DBMS, such as MySQL, as they may behave differently on different operation systems.


Creating Record
Expand Down Expand Up @@ -212,6 +215,15 @@ $post->createTime=new CDbExpression('NOW()');
$post->save();
~~~

> Tip: While AR allows us to perform database operations without writing
cumbersom SQL statements, we often want to know what SQL statements are executed
by AR underneath. This can be achieved by turning on the [logging feature](/doc/guide/topics.logging)
of Yii. For example, we can turn on [CWebLogRoute] in the application configuration,
and we will see the executed SQL statements being displayed at the end of each Web page.
Since version 1.0.5, we can set [CDbConnection::enableParamLogging] to be true in
the application configuration so that the parameter values bound to the SQL
statements are also logged.


Reading Record
--------------
Expand Down Expand Up @@ -555,7 +567,7 @@ $posts=Post::model()->published()->recently()->findAll();
In general, named scopes must appear to the left of a `find` method call. Each of them provides a query criteria, which is combined with other criterias, including the one passed to the `find` method call. The net effect is like adding a list of filters to a query.


===Parameterized Named Scopes
### Parameterized Named Scopes

Named scopes can be parameterized. For example, we may want to customize the number of posts specified by the `recently` named scope. To do so, instead of declaring the named scope in the [CActiveRecord::scopes] method, we need to define a new method whose name is the same as the scope name:

Expand All @@ -581,7 +593,7 @@ $posts=Post::model()->published()->recently(3)->findAll();
If we do not supply the parameter 3 in the above, we would retrieve the 5 recently published posts by default.


===Default Named Scope
### Default Named Scope

A model class can have a default named scope that would be applied for all queries (including relational ones) about the model. For example, a website supporting multiple languages may only want to display contents that are in the language the current user specifies. Because there may be many queries about the site contents, we can define a default named scope to solve this problem. To do so, we override the [CActiveRecord::defaultScope] method as follows,

Expand Down
38 changes: 37 additions & 1 deletion docs/guide/topics.url.txt
Expand Up @@ -106,6 +106,8 @@ corresponding to a single rule. The pattern of a rule is a string
used to match the path info part of URLs. And the route of a rule
should refer to a valid controller [route](/doc/guide/basics.controller#route).

### Using Named Parameters

A rule can be associated with a few GET parameters. These GET parameters
appear in the rule's pattern as special tokens in the following format:

Expand Down Expand Up @@ -167,11 +169,45 @@ when a user requests for `/index.php/post/100`, the second rule in the
above example will apply, which resolves in the route `post/read` and the
GET parameter `array('id'=>100)` (accessible via `$_GET`).


> Note: Using URL rules will degrade application performance. This is
because when parsing the request URL, [CUrlManager] will attempt to match
it with each rule until one can be applied. Therefore, a high-traffic Web
it with each rule until one can be applied. The more the number of rules,
the more the performance impact. Therefore, a high-traffic Web
application should minimize its use of URL rules.


### Parameterizing Routes

Starting from version 1.0.5, we may reference named parameters in the route part
of a rule. This allows a rule to be applied to multiple routes based on matching
criteria. It may also help reduce the number of rules needed for an application,
and thus improve the overall performance.

We use the following example rules to illustrate how to parameterize routes
with named parameters:

~~~
[php]
array(
'<_c:(post|comment)>/<id:\d+>/<_a:(create|update|delete)>' => '<_c>/<_a>',
'<_c:(post|comment)>/<id:\d+>' => '<_c>/read',
'<_c:(post|comment)>s' => '<_c>/list',
)
~~~

In the above, we use two named parameters in the route part of the rules:
`_c` and `_a`. The former matches a controller ID to be either `post` or `comment`,
while the latter matches an action ID to be `create`, `update` or `delete`.
You may name the parameters differently as long as they do not conflict with
GET parameters that may appear in URLs.

Using the aboving rules, the URL `/index.php/post/123/create`
would be parsed as the route `post/create` with GET parameter `id=123`.
And given the route `comment/list` and GET parameter `page=2`, we can create a URL
`/index.php/comments?page=2`.


### Hiding `index.php`

There is one more thing that we can do to further clean our URLs, i.e.,
Expand Down
8 changes: 7 additions & 1 deletion framework/YiiBase.php
Expand Up @@ -296,6 +296,7 @@ public static function setPathOfAlias($alias,$path)
* Class autoload loader.
* This method is provided to be invoked within an __autoload() magic method.
* @param string class name
* @return boolean whether the class has been loaded successfully
*/
public static function autoload($className)
{
Expand All @@ -305,7 +306,11 @@ public static function autoload($className)
else if(isset(self::$_classes[$className]))
include(self::$_classes[$className]);
else
include($className.'.php');
{
@include($className.'.php');
return class_exists($className,false);
}
return true;
}

/**
Expand Down Expand Up @@ -458,6 +463,7 @@ public static function t($category,$message,$params=array(),$source=null,$langua
'CApcCache' => '/caching/CApcCache.php',
'CCache' => '/caching/CCache.php',
'CDbCache' => '/caching/CDbCache.php',
'CDummyCache' => '/caching/CDummyCache.php',
'CEAcceleratorCache' => '/caching/CEAcceleratorCache.php',
'CMemCache' => '/caching/CMemCache.php',
'CXCache' => '/caching/CXCache.php',
Expand Down
25 changes: 25 additions & 0 deletions framework/base/CModule.php
Expand Up @@ -203,6 +203,31 @@ public function setImport($aliases)
Yii::import($alias);
}

/**
* Defines the root aliases.
* @param array list of aliases to be defined. The array keys are root aliases,
* while the array values are paths or aliases corresponding to the root aliases.
* For example,
* <pre>
* array(
* 'models'=>'application.models', // an existing alias
* 'extensions'=>'application.extensions', // an existing alias
* 'backend'=>dirname(__FILE__).'/../backend', // a directory
* )
* </pre>
* @since 1.0.5
*/
public function setAliases($mappings)
{
foreach($mappings as $name=>$alias)
{
if(($path=Yii::getPathOfAlias($alias))!==false)
Yii::setPathOfAlias($name,$path);
else
Yii::setPathOfAlias($name,$alias);
}
}

/**
* @return CModule the parent module. Null if this module does not have a parent.
*/
Expand Down

0 comments on commit 3aa81fa

Please sign in to comment.