maybeworks/yii2-libs 问题修复 & 功能扩展

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

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

maybeworks/yii2-libs

Composer 安装命令:

composer require maybeworks/yii2-libs

包简介

Library for Yii PHP framework 2.0

README 文档

README

Library for Yii PHP framework 2.0

Features:

  • Traits for ActiveRecord that add new functionality

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require "maybeworks/yii2-libs" "*"

or add

"maybeworks/yii2-libs" : "*"

to the require section of your application's composer.json file.

Usage

SearchTrait usage

use maybeworks\libs\SearchTrait;

class User extends ActiveRecord implements IdentityInterface {
    use SearchTrait;

    // [optional] default page size
    public $pageSize = 20;

    // ... other code ...

    public function init(){
        // add validators
        $this->searchInit();
    }

    // filter by LIKE %..%
    public function filterLikeAttributes() {
        return [
     	    'id',
     		'username',
     		'email',
     		'first_name',
     		'last_name',
     		'comment',
     	];
    }

    // filter by column = "value"
    public function filterAttributes() {
        return [
     	    'id',
     		'status',
     		'created_at',
     		'updated_at',
     		'last_visit',
     	];
    }
}

$list = User::forSearch(['email'=>'gmail.com']);

/* 
* or by form post
* 
* $item = new User();
* $item->load(Yii::$app->request->post());
* $list = $item->search();
* 
* or by direct value set
* $item = new User();
* $item->email = 'gmail.com';
* $list = $item->search();
*/

foreach ($list->getModels() as $user){
    echo $user->email;
}

AdditionsTrait usage

use maybeworks\libs\AdditionsTrait;


// get new record
$user = User::getItem();

// get record by ID
$user = User::getItem(10);

// get record copy
$user = User::getItem(10);
$new = $user->copy;

?>

MaybeWorks
Nothing is impossible, limit exists only in the minds of...
maybe.works

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 4
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-02-03