Login +

Administration / Models

In the SillySmart Back Office, you can Create / Modify / Delete all the Model layer via the menu "Models".

For starters, you can generate the desired Models on the database of your choice:

Once generated, the Models are presented so:

For each table, the following files are generated:

  • Mvc/Models/Objects/Db.Object.model.php
  • Mvc/Models/Sql/Db.Object.sql.php

A class is generated containing all the setters for columns of the table.

These setters are generated from a casting MySQL => PHP and the various constraints of the DBMS (uniqueness, nullable, etc..)

The form of a Model allows you to specify "human" descriptions for the table and for all columns. These descriptions are used in the interface of Back Office client to accurately describe the contents of each field.

Below this page, you can view the current Model code and that calculated from the current table. If you change your table during this time, the following message will appear:

Your model isn’t up to date, you should update it.

So you can one-click synchronize your Model.

You can also add specific types to consolidate setters.

The setter will then contain the following code in addition:

if (!SLS_String::validateEmail($value))
    $this->_typeErrors['author_email'] = "E_TYPE";
    return false;

List of all specifics types :

  • Address, helper with gMaps auto-complete
  • Color, validation hexadecimal of length 6
  • Email, validation with regular expression
  • File_all, validation with upload file
  • File_img, validation with upload file+thumbnail creationifdesired
  • IP_both, validation de type regex ipv4 ou ipv6
  • IP_V4, validation with regular expression
  • IP_V6, validation with regular expression
  • Position, move automatically others recordsets
  • Uniqid, generation of unique token
  • URL, validation with regular expression
  • Numeric (>0 | >=0 | <0 | <=0)
  • Complexity (lower|upper|alpha|special_char|number|min_length)

You can also add as many cleaning filters as you like.

The setter will then contain the following code in addition:

$value = SLS_String::filter($value, "lower");

List of different cleaning up filters:

  • Alpha, retains only the letters A-Z, a-z
  • Alpha numeric, retains only the lettersA-Z, a-z and numbers 0-9
  • Numeric, retains only numbers 0-9
  • Lowercase, passes the string to lower case
  • Lowercase First, passes the string first letter to lower case
  • Uppercase, passes the string to upper case
  • Upperrcase First, passes the string first letter to upper case
  • Uppercase Words, passes the first letters of each words in string to upper case
  • Trim, removes spaces at right and left of the string
  • Trim left, removes spaces at left of the string
  • Trim right, removes spaces at right of the string
  • No Space, removes all spaces from the string
  • Sanitize, cleans the address so you can passin the URL
  • Strip Tags, removes the HTML and PHPc ode from the string
  • Hash, hash the string

You can also specify Foreign Key from your columns (here on the table article):

If your database storage engine accepts intregity constraints (innoDB), foreign keys are automatically setted in the Model.

The setter will then contain the following code instead of previous:

public function setAuthorId($value)
    $object = new Main_Author();
    if ($object->getModel($value) === false)
        $this->_typeErrors['author_id'] = "E_KEY";
        return false;
    $this->__set('author_id', $value);
    return true;

Related :


  1. SLS_String - Tool SLS_String - String Treatment