2017 © Pedro Peláez
 

library ks

A lightweight PHP library

image

kenai/ks

A lightweight PHP library

  • Sunday, December 3, 2017
  • by Omar Gonzalez Rocha
  • Repository
  • 2 Watchers
  • 6 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

KS PHP

What is this?

A small PHP library for CRUD like apps

  • The main design criteria for this library was to make my life easier as a freelance web dev
  • It uses an Active record class that creates a table with given model
  • The model has convenience methods to interact with the DB records
  • HTML Output class that will build Components and Forms based on models

Prerequisites

  • PHP7
  • Strict types enabled
  • MySQL or Maria DB

Plays nice with

  • Any shared host with PHP7
  • Twitter Bootstrap
  • Need REST end points? Slim is pretty great

Config

  • Fill Config.php
      const DEBUG_MODE = true;
      const TIME_ZONE = "America/Mexico_City";
      const HOST = "host=127.0.0.1:8889";
      const DB = "KS";
      const DB_USER = "root";
      const DB_PW = "1111";

Classes

KS\DB - Convinience methods for DB interaction

  • Execute a SQL statement, returns a PDOStatement
    DB::sql("SELECT * FROM `cats`")->fetchAll();
  • Returns a new instance of PDO with Config.php params
    $pdo = DB::pdo(); 

KS\MODEL - Active Record Classes for BD Interaction

1-Extend a new custom model from KS\Model, (*1)

2-Assign public properties with type:, (*2)

    class Cat extends KS\Model\Model
    {
        public $name = "string"; //string
        public $age = 1; //integer
        public $is_fat = true; //boolean
    }

3 - KS\Model will automatically create a table, (*3)

4 - Use chained methods to manipulate the db, (*4)

     //Save new Model
     $c = new Cat();
     $c->name = "Odin";
     $c->age = 6;
     $c->is_fat = true;
     $c->save();

     //Or save new record with a $_POST array
     $c->save($_POST);

     //Find row with id 
     Cat::find(1)->get(); 

     //Return type json/object
     Cat::find(1)->json();
     Cat::find(1)->object();

     //Update with id 
     $c = new Cat();
     $c->name = "Odin";
     $c->age = 7;
     $c->is_fat = false;
     $c->update(1);

     //Delete with id
     Cat::delete(1);

KS\HMTL - for HTML output

The Versions

03/12 2017

dev-master

9999999-dev

A lightweight PHP library

  Sources   Download

MIT

by Avatar Omar Gonzalez Rocha

01/05 2017

dev-KS#2-Save-and-update-with-$_POST

dev-KS#2-Save-and-update-with-$_POST

A lightweight PHP library

  Sources   Download

MIT

by Avatar Omar Gonzalez Rocha

24/04 2017

dev-KS#8-Remove-unnecesary-name-spaces

dev-KS#8-Remove-unnecesary-name-spaces

A lightweight PHP library

  Sources   Download

MIT

by Avatar Omar Gonzalez Rocha

24/04 2017

dev-KS#3-sql-statement-db

dev-KS#3-sql-statement-db

A lightweight PHP library

  Sources   Download

MIT

by Avatar Omar Gonzalez Rocha

24/04 2017

dev-KS#5-Remove-KS-prefix

dev-KS#5-Remove-KS-prefix

A lightweight PHP library

  Sources   Download

MIT

by Avatar Omar Gonzalez Rocha