Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of chema garrido  >  PHP Redis Model  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example
Class: PHP Redis Model
CRUD operations to store and retrieve in Redis
Author: By
Last change:
Date: 2013-02-12 03:28
Size: 1,205 bytes
 

Contents

Class file image Download
<?php 
//main class to extend usage
require 'remodel.php';

//loading library predis: https://github.com/nrk/predis
require 'predis-0.8/autoload.php';
Predis\Autoloader::register();

///MODEL EXAMPLE
class Model_Post extends Remodel {

    protected 
$_table_name  'posts';
    protected 
$_primary_key 'id_post';

    
//NOT MANDATORY but recommended
    
protected $_fields = array( 'id_post',
                                
'title',
                                
'description',
                                
'created',
                                
'status',        
                                );
}

//CREATE:
$post = new Model_Post();
$post->title         'test title'.time();
$post->description     'test description';
$post->created         time();
$post->status         1;

$post->save();

print_r($post->values());

//GET an specific model 
$post = new Model_Post();
$post->load(1);
print_r($post->values());

//UPDATE current needs to be loaded before
$post->title  'title updated';
$post->status 0;
$post->save();
print_r($post->values());

//DELETE current
$post->delete();

//GET many
$post  = new Model_Post();
$posts $post->select(0,3);
foreach (
$posts as $p
    
print_r($p->values());