My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for

EnLib » System engine

  • MVC (Days_Model, Days_View, Days_Controller) - basic concepts necessary to work with framework
  • Days_Config - work with the configuration of the site
  • Days_Db - work with database
  • Days_Db_Table - implementation ORM representation of database tables
  • Days_Engine - starting point of entry
  • Days_Event - implementation of observer design pattern
  • Days_Log - logging errors and debugging information
  • Days_Request - request from the user's browser
  • Days_Response - response to the user's browser
  • Days_Url - work with the url address

Under development

  • Days_Acl (Aceess Control List) - delineation of rights of access to sections of the site
  • Days_Filter - filtering data coming from the user (also known as validation or verification of data)
  • Days_Form - processing of data coming from html forms
  • Days_User - work with user (authorization, authentication, end of session)
EnLibDaysDbTable  
ORM to work with tables.
Lang-En
Updated Nov 30, 2009 by anton.danilchenko

General information

ORM - allows you to work with the database as if you are working with objects of language php. You do not have to write SQL queries to obtain or save data. Instead, you must call the methods for obtaining data.

ORM will help you to accelerate the application development and simplify the process of further changes in the application.

How work ORM

Create a class for the desired table blog_category (stores category posts). To do this we create a file "/var/www/myblog/app/Model/Table/Blog/Category.php" with class definition:

<?php
class Model_Table_Blog_Category extends Days_Db_Table {
    protected $_name = 'blog_category';
}

Get the necessary table object. This is done as follows:

$tableBlogCategory = Days_Model::factory('table_blog_category');

Obtain data from a table:

// obtain information about a category
$category = $tableBlogCategory->find('one', array('where'=>array('id'=>10)));
// obtain all categories
$categories = $tableBlogCategory->find('all');
// obtain 20 subcategories
$subcategories = $tableBlogCategory->find('all', array(
  // return sub-categories with id=10
  'where' => array(
    'pid' = 10
  ),
  // returns the first 20 rows
  'count' => 20
));
// obtain the total count of subcategories
$countCategories = $tableBlogCategory->find('count', array(
  // return sub-categories with id=10
  'where' => array(
    'pid' = 10
  )
));
// obtain the first 15 categories
$firstCaterories = $tableBlogCategory->find('first', array(
  'count' => 15
));
// delete category
$category->delete();
// remove all the categories included in the set
$firstCaterories->delete();
// create a new row
$newRow = $subcategories->create();
$newRow->name = 'New subcategory';
// save row
$newRow->save();

Using Days_Db_Table

Is a representation of a real table, and allows you to perform operations on this table.

  • find($type, $cond) - obtain the result in specified form
    • $type - in what form to return the result
      • all: all rows
      • first: all rows with sorting by date (свежие записи будут первыми)
      • last: all rows with sorting by date (свежие записи будут последними)
      • one: one row
      • count: total number of rows (lines themselves are not returned)
    • $cond - conditions imposed on the result
      • count (int): count of rows in result set
      • page (int): current page number (start from 1)
      • columns (array): column names
      • where (array): pairs column=>$value or column_with_value
      • group (array): group by columns
      • order (array): sorting by columns
  • create() - creates a new empty Rowset
  • save(Days_Db_Row $row) - save specified row
  • delete(Days_Db_Row $row) - delete specified row
  • join($table) - attach the specified table to the result

Using Days_Db_Rowset

Represents a set of rows Days_Db_Row. Allows you to change the set of rows.

  • create(array $data=array()) - create new row Days_Db_Row
  • save(Days_Db_Row $row) - save specified row
  • delete(Days_Db_Row $row) - delete specified row
  • count() - number of rows in a given set
  • toArray() - returns a set of rows as an array

Also provides data from the current row, as if we are working with this row.

// displays the name of the first category
echo $categories->name;

Using Days_Db_Row

Represents a table row and allows you to work with it.

  • save() - save the current line
  • delete() - delete the current line
  • toArray() - returns the current row as an array
  • parent - getting all parent elements (if you have a column id and pid)
  • child - getting all child elements (if you have a column id and pid)
  • table_name - getting related records from the specified table (for categories of table blog_category object table blog need to specify just category instead of blog_category)

Sign in to add a comment
Powered by Google Project Hosting