Jump to content

Ocs-server/Gfx4/Models

From KDE Community Wiki
Revision as of 11:03, 27 July 2015 by Snizzo (talk | contribs) (Created page with "The '''EModel''' class contains various facilities for querying databases and performing standard tasks like SELECT, INSERT, UPDATE and DELETE. So, for example, if you're writ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The EModel class contains various facilities for querying databases and performing standard tasks like SELECT, INSERT, UPDATE and DELETE. So, for example, if you're writing a class that interfaces with the "posts" class in your database, you should create a file name "posts.model.php" in the "model" directory. GFX already knows that there are models there. This is a convention when creating models directly binded to a database table but feel free to create models with custom names. There is no particular restriction on Model's use.

Every model should be name following this syntax <tablename>.model.php in order to be automatically loaded by gfx as a model. Then you can write your code that basically queries the database and returns the correct data, along with all manipulations done.

Think of a Model of an object that has to return data that should already human understandable if seen raw.


This is an example of a basic model class:

   <?php
   class ArticlesModel extends EModel
   {
       public function __construct()
       {
           parent::__construct("articles");
       }
       
       public function getAll()
       {
           $data = $this->find("*");
           return $data;
       }
   }
   ?>