定制 yohancayres/crud-advanced 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

yohancayres/crud-advanced

Composer 安装命令:

composer require yohancayres/crud-advanced

包简介

This class is a Crud with advanced methods. Provides agility and productivity in development. Edit

README 文档

README

This class is a Crud with advanced methods. Provides agility and productivity in development.

All the methods and a description about them will be listed below. All class Crud.class.php is documented.

Installation

Install Manually

You can install CrudAdanved manually

require_once "src/CrudAdvanced/DataBase.php";
require_once "src/CrudAdvanced/Val.php";
require_once "src/CrudAdvanced/Crud.php";

use CrudAdvanced\DataBase;
use CrudAdvanced\Val;
use CrudAdvanced\Crud;

Install with Composer

You can install CrudAdanved with composer With command:

composer require yohancayres/crud-advanced

or adding in composer.json

{
    "require": {
        "yohancayres/crud-advanced": "dev-master"
    }
}

Available Methods

Generic Methods

  • _set($key, $value) - Set or change the value of an attribute;
  • _get($key) - Get the value of an attribute;
  • loadData(array $data) - Loads data from an array to object attributes;
  • requiredParam(array $params) - Checks whether the required attribute exists;
  • getParamArray(array $params) - Get an array of object attributes;

Databases Methods

  • dbInsert() - Inserts the attributes of the object in the database;
  • dbUpdateAll() - Refreshes all attributes in the database;
  • dbUpdateAtts($atts) - Updates specific attributes in the database;
  • dbUpdate($attr, $newvalue) - Defines and updates the value of an attribute in the database;
  • dbUpdateIncrease($attr, $amount) - Updates an attribute by incrementing its value (this value can be negative);
  • dbSearch($attr, $data) - Searches the database;
  • dbRemove() - Removes a record from the database;
  • dbCheckExists($attr) - Checks whether a record already exists;
  • dbLoadData($values) - Loads all data from the database;
  • dbLoadDataBy($attr, $values) - Loads all database data using an attribute defined by the first parameter;
  • fetchById($id, $values) - Get database record;
  • fetchRandom($values) - Gets a random record of the database;
  • fetchAll($where, $loadAtts) - Get all records from the table;

Relationship

  • hasOne($className, $thisAttName, $classAttName, $loadAtts)- Creates a one-to-one relationship;
  • hasMany($className, $thisAttName, $classAttName, $loadAtts) - Creates a one-to-many relationship;

Examples

Connect to the Database

First of all, the application needs information to connect to the database

use CrudAdvanced\DataBase;

DataBase::configure('127.0.0.1', 'root', 'password', 'dbteste');

Using Crud

To create a class and use the Crud Methods, you need to extends Crud to your class.

use CrudAdvanced\Val;
use CrudAdvanced\Crud;

class User extends Crud {

	/* Database table definition */
	public $table = "users"; // Define Table name
	public $tableCols = ['name', 'email', 'password']; // Define table cols

	/*
	 * Other class methods and attributes can be defined freely.
	 */
}

Insert new user with dbInsert()

This method will insert all the attributes to the database. Be aware of the name of the attributes, they must be exactly the same as the fields in the database.

$user = new User([
	'name' => 'Yohan Cayres',
	'email' => 'yohan.cayres@mail.com',
	'password' => md5('somepassword')
]); // Create new object type User

$user->dbInsert(); // Insert at the Database

dbLoadDataBy()

This method will load attributes from database, making the search for the defined attribute.

$user->dbLoadDataBy('email', 'id,name,password'); // Loads a database attribute by email.
echo $user->_get('id');

Update some row with dbUpdateAll() or dbUpdateAtts()

This method needs the id attribute, you can get it through dbLoadDataBy();

$user->_set('email', 'newMail@mail.com'); // This will set a new email

$user->dbUpdateAtts('email'); // Only the attribute 'email' will be updated
$user->dbUpdateAll(); // All the attributes will be updated

Update directly

This method needs the id attribute, you can get it through dbLoadDataBy();

$user->dbUpdate('email', 'newMail@mail.com'); // Set and update directly.

Hosting Options

Web Hosting VPS Windows VPS Linux

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-04-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固