| 
<?php
 /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 require_once 'VsActiveRecord.php';
 
 class Post extends VsActiveRecord {
 public function __construct($id = NULL) {
 $this->init('tbl_post', 'id', $id);
 if(!is_null($id)) {
 $this->load();
 }
 }
 
 public static function collection($nameAR = __CLASS__) {
 return parent::collection($nameAR);
 }
 }
 
 
 function printObject(VsActiveRecord $obj) {
 foreach($obj->getColumns() as $k=>$v){
 echo $k.' => '. $v.'<br/>';
 }
 echo '<hr/>';
 }
 
 /**
 * Create new Post
 */
 $u = new Post();
 $u->title  = 'Some title';
 $u->content = 'Some text ';
 $u->author_id = 1;
 $u->update();
 printObject($u);
 
 
 /**
 * Create new Post
 */
 $u = Post::collection()->create(array(
 'title'=>'Some title 2',
 'content'=>'Some text 2',
 'author_id'=>2,
 ));
 printObject($u);
 
 /**
 * Find  Post
 */
 $posts = Post::collection()->find( 'author_id = 2', null, 2);
 foreach($posts as $u) {
 printObject($u);
 }
 echo ('Size find rows: '.Post::collection()->getSizeLastQuery());
 echo '<hr/>';
 
 /**
 *Update Posts
 */
 $posts = Post::collection()->update(array('title'=>'new title'), 'author_id = 1');
 foreach($posts as $u) {
 printObject($u);
 }
 
 /**
 *Remove Posts
 */
 Post::collection()->delete('author_id = 2');
 
 
 
 ?>
 
 |