consultnn/yii2-mongodb-embedded 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

consultnn/yii2-mongodb-embedded

最新稳定版本:v1.0.5

Composer 安装命令:

composer require consultnn/yii2-mongodb-embedded

包简介

Yii2 behaviors implement handling of mongodb embedded documents

README 文档

README

  • Add attribute with name starting with underscore to model.
/**
* @inheritdoc
*/
public function attributes()
{
    return [
        '_address',
        '_phones',
    ]
}
  • Add "safe" validation rule for attribute without underscore in name.
/**
 * @inheritdoc
 */
public function rules()
{
    return [
            [['address', 'phones'], 'safe'],
        ]
}
  • Add behavior with attribute name with underscore in name
'address' => [
    'class' => EmbedsOneBehavior::className(),
    'attribute' => '_address',
    'embedded' => Address::className()
],
'phones' => [
    'class' => EmbedsManyBehavior::className(),
    'attribute' => '_phones',
    'embedded' => Phone::className()
],
class Phone extends EmbeddedDocument 
{
    public $number;
    public $type;
    
    public function rules()
    {
        return [
            [['number', 'type'], 'string'],
            [['type'], 'in', 'range' => ['home', 'work']],
        ];
    }
}
  • To create empty embedded document set base document's scenario to the value listed in initEmptyScenarios parameter of EmbedsManyBehavior
'address' => [
    'class' => EmbedsOneBehavior::className(),
    'attribute' => '_address',
    'initEmptyScenarios' => ['create', 'update'],
    'embedded' => Address::className()
],
  • Use attribute without underscore in form or view
// Address
echo $form->field($company->address, 'detail');
echo $form->field($company->address, 'id')->hiddenInput();

// Phones
foreach($company->phones as $key => $phone) {
    echo $form->field($phone, 'number');
    echo $form->field($phone, 'type');
}

统计信息

  • 总下载量: 4.84k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 17
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-04-08