承接 wdes/simple-php-model-system 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

wdes/simple-php-model-system

最新稳定版本:v1.3.0

Composer 安装命令:

composer require wdes/simple-php-model-system

包简介

A simple PHP model system

README 文档

README

Lint and analyse files Run phpunit tests codecov Version License PHP Version Require maintenance-status

A simple PHP model system

Why ?

The goal of this project is to provide an easy way to use Models in a non composer setup. This is why this project is kept very minimal. The user can copy all classes in src/ and start using the lib. But this also works in a composer setup.

How to use

Connect to an existing PDO connection

<?php
declare(strict_types = 1);

use SimplePhpModelSystem\Database;

require_once __DIR__ . DIRECTORY_SEPARATOR . 'autoload.php';// Use your autoloader or require classes by hand

$db         = new Database(null);
// With Symfony: EntityManagerInterface $em
$db->setConnection($em->getConnection()->getNativeConnection());// Wants a PDO connection object class

Connect with config

<?php
declare(strict_types = 1);

use SimplePhpModelSystem\Database;

require_once __DIR__ . DIRECTORY_SEPARATOR . 'autoload.php';// Use your autoloader or require classes by hand

$configFile = __DIR__ . DIRECTORY_SEPARATOR . 'config.php';// Copy config.dist.php and fill the values
$config     =  require $configFile;
$db         = new Database($config);
$db->connect();// Will throw an exception if not successfull

Manage models

<?php

use examples\User;

// Without models

$statement = $db->query(
    'SELECT 1'
);
$this->data = [];
while (($row = $statement->fetch(PDO::FETCH_ASSOC)) !== false) {
    $this->data[] = $row;
}
var_dump($this->data);


// With a model

$user1 = User::create(
    '5c8169b1-d6ef-4415-8c39-e1664df8b954',
    'Raven',
    'Reyes',
    null
);
$user1->save();// If you forget this line, it will only exist in memory
$user1 = User::findByUuid('5c8169b1-d6ef-4415-8c39-e1664df8b954');// Find the user back
$user1->toArray();
//[
//    'user_uuid' => '5c8169b1-d6ef-4415-8c39-e1664df8b954',
//    'first_name' => 'Raven',
//    'last_name' => 'Reyes',
//    'date_of_birth' => null,
//]
$user1->refresh(); // Get it back from the DB
$user1->setLastName('last_name', 'Ali-2');// Change an attribute value (build your own setters using the example)
$user1->update();// Update it
$user1->delete();// Delete it
User::deleteAll();// Delete all
// And more functions, see AbstractModel class

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MPL-2.0
  • 更新时间: 2021-05-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固