Overview

Namespaces

  • Sleepy
  • Module
    • Authentication
    • CSV
    • DB
    • FormBuilder
    • FSDB
    • IP2Country
    • Mailer
    • MobiDetect
    • Navigation
    • StaticCache
  • PHP

Classes

  • DB
  • Grid
  • Record
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo

Class Record

Base class that represents a record in a table.

Extend this class and add a property $table that is equal to the table name in your database. The columns will be loaded automatically and basic load(), save(), and delete() methods are immediately available. Update the data by changing the value of the columns like this:

Usage

// load a record with id= 5 from a table called 'user'
  class user extends \Module\DB\Record {
    public $table = 'user';
  }

  $u = new user();
  $u->load(5);
  $u->columns['first_name'] = 'Joe';

You can then save the new information by calling the save method:

$u->save();

You can also show a nice form to edit or add new records like this

$u->form(array(
    'first_name' => 'First Name: ',
    'last_name' => 'Last Name: ',
    'phone' => '(800) 555-5555'
  ));

Changelog

Version 1.2

  • Added namespacing

Version 1.1

  • Added the date section to the documentation

Direct known subclasses

Module\Authentication\Permission, Module\Authentication\Role, Module\Authentication\User, Module\Authentication\UserMeta
Namespace: Module\DB
License: http://opensource.org/licenses/MIT
Author: Jaime A. Rodriguez hi.i.am.jaime@gmail.com
Version: 1.1
Date: June 16, 2014
Section:

dependencies Dependencies * class.hooks.php * class.db.php


Located at class.record.php
Methods summary
public
# __construct( string $id = 0 )

Initializes db and gets column information.

Initializes db and gets column information.

Parameters

$id
The id to load automatically
public boolean
# load( integer $id = 0 )

Loads a record as an object.

Loads a record as an object.

Parameters

$id
id of a record to load

Returns

boolean
True if loaded correctly
public mixed
# save( )

Saves the record to the database.

Saves the record to the database.

Returns

mixed
Returns the Primary Key
public boolean
# delete( )

Deletes this record from the database

Deletes this record from the database

Returns

boolean
True if delete is successful
public
# form( array $fields, string $legend = 'table_name', boolean $submit = true )

Shows an editable form

Shows an editable form

Parameters

$fields
An array of columns => labels
$legend
Customize the fieldset legend
$submit
Show the submit button?

Returns


returns nothing
Properties summary
protected $db

PDO The PDO object

PDO The PDO object

#
protected $table

string The name of the table

string The name of the table

#
protected string $primaryKey

string The primary key of the table

string The primary key of the table

# 'id'
public $columns

array The data of the record get loaded here

array The data of the record get loaded here

#
public $meta

stdObject The record meta data gets loaded here

stdObject The record meta data gets loaded here

#
sleepyMUSTACHE v.0.8 API documentation generated by ApiGen