iachilles / eavactiverecord
实现了实体-属性-值模式,并提供了一种简单的方式来处理EAV属性。
Requires
- php: >=5.1.0
README
实现了实体-属性-值模式,并提供了一种简单的方式来处理EAV属性。EAV属性作为单独的记录存储在数据库中,但以类似实体表列的方式访问和搜索。
以下功能受支持
- 延迟和懒加载EAV属性。
- 动态验证规则。为EAV属性定义的验证规则将被动态添加到模型中。
- 自动插入/更新/删除EAV属性值。
- 以与模型真实属性相同的方式访问和编辑EAV属性。
- 使用find方法通过EAV属性进行简单搜索。
要求
- Yii 1.1.2或更高版本
- PHP 5.1或更高版本
安装
-
在“protected/components/eavactiverecord”文件夹下下载并解压发布文件。
-
运行SQL脚本mysql.sql或postgresql.sql(如果您使用的是PostgreSQL数据库)它位于以下文件夹:“protected/components/eavactiverecord/schema/”。它创建了用于处理EAV属性所需的表:eav_set, eav_attribute, eav_attribute_set, eav_attribute_date, eav_attribute_int, eav_attribute_varchar, eav_attribute_text。
-
在文件“protected/config/main.php”中添加以下行
array( 'import' => array( 'application.components.eavactiverecord.', 'application.components.eavactiverecord.datatypes.', 'application.components.eavactiverecord.helpers.*' )
1. It requires cache to be activated in the application:
```php
array(
…
'components'=>array(
…
'cache'=>array(
'class'=>'system.caching.CMemCache',
'servers'=>array(
array('host'=>'server1', 'port'=>11211, 'weight'=>60),
array('host'=>'server2', 'port'=>11211, 'weight'=>40),
),
),
),
);
如果定义为以下内容,则扩展将使用自己的缓存组件
array( … 'components'=>array( … 'eavCache'=>array( 'class'=>'system.caching.CMemCache', 'servers'=>array( array('host'=>'server1', 'port'=>11211, 'weight'=>60), array('host'=>'server2', 'port'=>11211, 'weight'=>40), ), ), ), );
如果您不使用缓存,请在文件“protected/config/main.php”中添加以下代码
'components' => array( 'eavCache' => array( 'class' => 'system.caching.CDummyCache' ), )
-
从类EavActiveRecord扩展您的模型类
class Foo extends EavActiveRecord
1. Call the method Foo::addColumn(). This method must only be called once for each model that extends EavActiveRecord class.
It adds the new column "eav_set_id" in the associated database table.
```php
Foo::model()->addColumn();
-
自v1.0.2起,它包括基于扩展API的用户交互GUI模块(前端模块)。有关安装模块的详细信息,请参阅EavModule安装指南
##接下来是什么?
有关如何使用eavactiverecord扩展的详细信息,请阅读以下wiki文章