satthi / entity-column-check

CakePHP EntityColumnCheck

安装次数: 28,644

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

公开问题: 0

类型:cakephp-plugin

0.1.3 2017-02-20 10:56 UTC

This package is auto-updated.

Last update: 2024-09-22 13:00:19 UTC


README

Build Status Scrutinizer Code Quality

此插件是用于在CakePHP3的Entity中,当属性设置与数据库列不匹配时,除了特定的例外列外,将返回Exception的插件

  • 属性设置的
  • 对应数据库的列
  • 特定异常的列

以外的列被设置时,会返回Exception

安装

composer.json

{
	"require": {
		"satthi/entity-column-check": "*"
	}
}

composer install

使用方法

实体

<?php
namespace App\Model\Entity;

use Cake\ORM\Entity;
use EntityColumnCheck\Model\Entity\EntityColumnCheckTrait;

class Topic extends Entity
{
    // 追加項目
    use EntityColumnCheckTrait;
    protected $_accessible = [
        '*' => true,
        'id' => false
    ];
    // 例外として設定するカラム
    protected $entityColumnCheckAllowField = [
        'file',
        'img'
    ];

    //&getメソッドをoverride
    public function &get($property)
    {
        $value = parent::get($property);
        $this->getEntityColumnCheck($property);
        return $value;
    }
}