iachilles/eavactiverecord

实现了实体-属性-值模式,并提供了一种简单的方式来处理EAV属性。

安装: 29

依赖项: 0

建议者: 0

安全: 0

星标: 9

关注者: 2

分支: 6

开放问题: 0

类型:yii-extension

1.0.4 2014-11-19 11:27 UTC

This package is auto-updated.

Last update: 2024-09-22 05:16:08 UTC


README

实现了实体-属性-值模式,并提供了一种简单的方式来处理EAV属性。EAV属性作为单独的记录存储在数据库中,但以类似实体表列的方式访问和搜索。

以下功能受支持

  • 延迟和懒加载EAV属性。
  • 动态验证规则。为EAV属性定义的验证规则将被动态添加到模型中。
  • 自动插入/更新/删除EAV属性值。
  • 以与模型真实属性相同的方式访问和编辑EAV属性。
  • 使用find方法通过EAV属性进行简单搜索。

要求

  • Yii 1.1.2或更高版本
  • PHP 5.1或更高版本

安装

  1. 在“protected/components/eavactiverecord”文件夹下下载并解压发布文件。

  2. 运行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。

  3. 在文件“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'
     ),
  )
  1. 从类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();
  1. 自v1.0.2起,它包括基于扩展API的用户交互GUI模块(前端模块)。有关安装模块的详细信息,请参阅EavModule安装指南

    以下为模块页面的截图 EavModule screenshot


##接下来是什么?

有关如何使用eavactiverecord扩展的详细信息,请阅读以下wiki文章

  1. 快速入门指南
  2. 管理EAV属性
  3. 管理EAV属性集
  4. 在模型中使用EAV属性
    1. 将EAV属性附加到模型
    2. 为EAV属性赋值
    3. 访问EAV属性值
    4. 保存EAV属性值
    5. 删除EAV属性值
    6. EAV属性值的延迟和懒加载
    7. 通过EAV属性搜索
    8. 属性的优先级
  5. 使用EavForm小部件创建EAV属性的表单元素
  6. API文档