2017 © Pedro Peláez
 

library php-orm-pdo

Micro PHP ORM Library

image

arojunior/php-orm-pdo

Micro PHP ORM Library

  • Sunday, July 23, 2017
  • by arojunior
  • Repository
  • 3 Watchers
  • 2 Stars
  • 85 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 4 Versions
  • 4 % Grown

The README.md

Installing via composer and using as a lib

composer require arojunior/php-orm-pdo

create a file to overwrite the database config

use SimpleORM\core\model\Model;

class AppModel extends Model
{
    public $db_config = [
        'db_host' => '192.168.1.1',
        'db_name' => 'test',
        'db_user' => 'root',
        'db_pass' => ''
    ];
}

And then you can extend this class in your classes

use YourNamespace\AppModel;

class Example extends AppModel
{
    public $table = 't_user';
    public $pk    = 'user_id';

    public function getAll()
    {
        return $this->findAll();
    }
}

CRUD


namespace SimpleORM\app\model; use SimpleORM\core\model\Model; class Users extends Model { /* * * Basic configuration * These arguments are optionals * protected $table = 'users'; //just if the class name a table name are different * protected $pk = 'id'; //just if the primary key name is not id */ }

Creating a new user (without check)

$this->Users->create([
  'name' => 'Junior Oliveira',
  'email' => 'arojunior@gmail.com'
]);

Let the ORM choose if it will be created or updated. The ORM will execute the find method before to decide if will create or update data, (*1)

Saving data

$this->Users->save([
  'id' => 1,
  'name' => 'Junior Oliveira'
]);

Retrieving the id

$this->Users->lastSavedId();

Updating a user with id = 1

$this->Users->update([
  'id' => 1,
  'email' => 'contato@arojunior.com'
]);

Delete

$this->Users->delete(['id' => 1]);

Read

$this->Users->findAll(); // fetchAll

$this->Users->findOne(['email' => 'arojunior@gmail.com']);

$this->Users->findById($id);

Checking

$this->Users->exists($id);

in case of true, you cat get the data with:, (*2)

$this->Users->fetch();

Functionalities if used as Framework

  • CRUD functions
  • Auto load Model classes in Controllers
  • To use the automatic functions you should use the filename and structure conventions
  • Just follow the example on /controller/UsersController.php
  • All controllers in /app/controllers folder
  • All models in /app/models folder

Convetions

  • All controllers in /app/controller path
  • All models in /app/model path
  • All views in /app/view path
  • Filenames and classes must has the same name

The Versions

23/07 2017

dev-master

9999999-dev

Micro PHP ORM Library

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Junior Oliveira

23/07 2017

dev-scrutinizer-patch-1

dev-scrutinizer-patch-1

Micro PHP ORM Library

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Junior Oliveira

14/03 2017

1.1

1.1.0.0

Micro PHP ORM Framework

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Junior Oliveira

10/11 2016

1.0

1.0.0.0

Micro PHP ORM Framework to solve basic problems

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Junior Oliveira