Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * TActiveRecordConfig class file.
4
 *
5
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
6
 * @link http://www.pradosoft.com/
7
 * @copyright Copyright &copy; 2005-2008 PradoSoft
8
 * @license http://www.pradosoft.com/license/
9
 * @version $Id: TActiveRecordConfig.php 2541 2008-10-21 15:05:13Z qiang.xue $
10
 * @package System.Data.ActiveRecord
11
 */
12
 
13
Prado::using('System.Data.TDataSourceConfig');
14
 
15
/**
16
 * TActiveRecordConfig module configuration class.
17
 *
18
 * Database configuration for the default ActiveRecord manager instance.
19
 *
20
 * Example: application.xml configuration
21
 * <code>
22
 * <modules>
23
 * 	<module class="System.Data.ActiveRecord.TActiveRecordConfig" EnableCache="true">
24
 * 		<database ConnectionString="mysql:host=localhost;dbname=test"
25
 * 			Username="dbuser" Password="dbpass" />
26
 * 	</module>
27
 * </modules>
28
 * </code>
29
 *
30
 * MySQL database definition:
31
 * <code>
32
 * CREATE TABLE `blogs` (
33
 *  `blog_id` int(10) unsigned NOT NULL auto_increment,
34
 *  `blog_name` varchar(255) NOT NULL,
35
 *  `blog_author` varchar(255) NOT NULL,
36
 *  PRIMARY KEY  (`blog_id`)
37
 * ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
38
 * </code>
39
 *
40
 * Record php class:
41
 * <code>
42
 * class Blogs extends TActiveRecord
43
 * {
44
 * 	public $blog_id;
45
 *	public $blog_name;
46
 *	public $blog_author;
47
 *
48
 *	public static function finder($className=__CLASS__)
49
 *	{
50
 *		return parent::finder($className);
51
 *	}
52
 * }
53
 * </code>
54
 *
55
 * Usage example:
56
 * <code>
57
 * class Home extends TPage
58
 * {
59
 * 	function onLoad($param)
60
 * 	{
61
 * 		$blogs = Blogs::finder()->findAll();
62
 *      print_r($blogs);
63
 * 	}
64
 * }
65
 * </code>
66
 *
67
 * @author Wei Zhuo <weizho[at]gmail[dot]com>
68
 * @version $Id: TActiveRecordConfig.php 2541 2008-10-21 15:05:13Z qiang.xue $
69
 * @package System.Data.ActiveRecord
70
 * @since 3.1
71
 */
72
class TActiveRecordConfig extends TDataSourceConfig
73
{
74
	private $_enableCache=false;
75
 
76
	/**
77
	 * Initialize the active record manager.
78
	 * @param TXmlDocument xml configuration.
79
	 */
80
	public function init($xml)
81
	{
82
		parent::init($xml);
83
		Prado::using('System.Data.ActiveRecord.TActiveRecordManager');
84
		$manager = TActiveRecordManager::getInstance();
85
		if($this->getEnableCache())
86
			$manager->setCache($this->getApplication()->getCache());
87
		$manager->setDbConnection($this->getDbConnection());
88
	}
89
 
90
	/**
91
	 * Set true to cache the table meta data.
92
	 * @param boolean true to cache sqlmap instance.
93
	 */
94
	public function setEnableCache($value)
95
	{
96
		$this->_enableCache = TPropertyValue::ensureBoolean($value);
97
	}
98
 
99
	/**
100
	 * @return boolean true if table meta data should be cached, false otherwise.
101
	 */
102
	public function getEnableCache()
103
	{
104
		return $this->_enableCache;
105
	}
106
}
107