|
EnLibDaysDbTable
ORM to work with tables.
Lang-En
General informationORM - 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 ORMCreate 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_TableIs a representation of a real table, and allows you to perform operations on this table.
Using Days_Db_RowsetRepresents a set of rows Days_Db_Row. Allows you to change the set of rows.
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_RowRepresents a table row and allows you to work with it.
| |