ice framework documentation ice doc v1.10.1
Methods
  • getDi() : void
  • getDb() : void
  • setFrom(variable $from) : void
  • setPrimary(variable $primary) : void
  • getPrimary() : void
  • setAutoincrement(variable $autoincrement) : void
  • setFilters(variable $filters) : void
  • getFilters() : void
  • setFields(variable $fields) : void
  • getFields() : void
  • setValidation(variable $validation) : void
  • getValidation() : void
  • getRelations() : void
  • setLabels(variable $labels) : void
  • getMessages() : void
  • setMessages(variable $messages) : void
  • __construct(variable $filters, array $data, array $options) : void
    Model constructor. Fetch Di and set it as a property.
  • getId() : void
    Get the id.
  • getIdKey() : string
    Get the id key depending on db driver.
  • getDateTime(variable $key, variable $model) : void
    Get the date time object.
  • loadOne(variable $filters, array $options) : void
    Load one result to the current object.
  • load(variable $filters, array $options) : void
    Load results to the current object.
  • findOne(variable $filters, array $options) : void
    Allows to query one record that match the specified conditions.
  • find(variable $filters, array $options) : void
    Allows to query all records that match the specified conditions.
  • fields(variable $fields, bool $primary) : void
    Prepare fields for validation on create/update.
  • create(variable $fields, variable $extra) : void
    Insert a new object to the database.
  • update(variable $fields, variable $extra) : void
    Update an existing object in the database.
  • save(variable $fields, variable $extra) : void
    Inserts or updates a model instance. Returning true on success or false otherwise.
  • delete(variable $filters) : void
    Removes a model instance(s). Returning true on success or false otherwise.
  • exists(variable $filters) : void
    Get the record if exist.
  • loaded() : bool
    Check whether model is loaded.
  • getError() : void
    Get the last Db error.
  • belongsTo(string $field, string $referenceModel, string $referencedField, array $options) : void
    Setup a relation reverse 1-1 between two models.
  • hasOne(string $field, string $referenceModel, string $referencedField, array $options) : void
    Setup a 1-1 relation between two models
  • hasMany(string $field, string $referenceModel, string $referencedField, array $options) : void
    Setup a relation 1-n between two models.
  • getRelated(string $alias, array $filters, array $options) : void
    Get related models.
  • getRules(variable $fields) : void
    Get rules for validation.
  • setRules(array $rules, bool $merge) : void
    Set rules for validation.
  • __serialize() : array
    Serialize the model's data.
  • __unserialize(array $serialized) : void
    Unserialize and set the data.
  • __call(string $method, variable $arguments) : void
    Magic call to get related models.
Methods Details
  • public function getDi()

  • public function getDb()

  • public function setFrom(variable $from)

  • public function setPrimary(variable $primary)

  • public function getPrimary()

  • public function setAutoincrement(variable $autoincrement)

  • public function setFilters(variable $filters)

  • public function getFilters()

  • public function setFields(variable $fields)

  • public function getFields()

  • public function setValidation(variable $validation)

  • public function getValidation()

  • public function getRelations()

  • public function setLabels(variable $labels)

  • public function getMessages()

  • public function setMessages(variable $messages)

  • public function __construct(variable $filters, array $data, array $options)

    Model constructor. Fetch Di and set it as a property.
  • public function getId()

    Get the id.
  • public function getIdKey()

    Get the id key depending on db driver.
  • public function getDateTime(variable $key, variable $model)

    Get the date time object.
  • public function loadOne(variable $filters, array $options)

    Load one result to the current object.
  • public function load(variable $filters, array $options)

    Load results to the current object.
  • public static function findOne(variable $filters, array $options)

    Allows to query one record that match the specified conditions.
    
          //Get the user from users by id 2
          $user = Users::findOne(2);
          echo "The user name is ", $user->username;
         
          //Get one active user with age > 18
          $user = Users::findOne(array("status" => 1, "age" => array(">" => 18)));
         
  • public static function find(variable $filters, array $options)

    Allows to query all records that match the specified conditions.
    
          //Get all active users with age > 18
          $user = Users::find(array("status" => 1, "age" => array(">" => 18)));
         
  • protected function fields(variable $fields, bool $primary)

    Prepare fields for validation on create/update.
  • public function create(variable $fields, variable $extra)

    Insert a new object to the database.
    
          //Creating a new user
          $user = new Users();
          $user->lastname = "Kowalski";
          $user->status = 1;
          $user->create();
         
  • public function update(variable $fields, variable $extra)

    Update an existing object in the database.
    
          //Updating a user last name
          $user = Users::findOne(100);
          $user->lastname = "Nowak";
          $user->update();
         
  • public function save(variable $fields, variable $extra)

    Inserts or updates a model instance. Returning true on success or false otherwise.
    
          //Creating a new user
          $user = new Users();
          $user->lastname = "Kowalski";
          $user->status = 1;
          $user->save();
         
          //Updating a user last name
          $user = Users::findOne(100);
          $user->lastname = "Nowak";
          $user->save();
         
  • public function delete(variable $filters)

    Removes a model instance(s). Returning true on success or false otherwise.
    
          //Remove current user
          $user = Users::findOne(100);
          $user->delete();
         
          //Remove all unactive users
          $status = (new Users())->delete(["status" => 0]);
         
  • public function exists(variable $filters)

    Get the record if exist.
  • public function loaded()

    Check whether model is loaded.
  • public function getError()

    Get the last Db error.
  • public function belongsTo(string $field, string $referenceModel, string $referencedField, array $options)

    Setup a relation reverse 1-1 between two models.
    
          class Posts extends Model
          {
              public function initialize()
              {
                  //Relation with user, be able to get post's author
                  $this->belongsTo('user_id', __NAMESPACE__ . '\Users', 'id', ['alias' => 'User']);
              }
          }
         
          //Get post's author
          $post = Posts::findOne(100);
          echo $post->getUser()->username;
         
  • public function hasOne(string $field, string $referenceModel, string $referencedField, array $options)

    Setup a 1-1 relation between two models
    
          class Users extends Model
          {
              public function initialize()
              {
                  $this->hasOne('id', __NAMESPACE__ . '\UsersDescriptions', 'user_id', ['alias' => 'Description']);
              }
          }
         
  • public function hasMany(string $field, string $referenceModel, string $referencedField, array $options)

    Setup a relation 1-n between two models.
    
          class Users extends Model
          {
              public function initialize()
              {
                  //Relation with posts, be able to get user's posts
                  $this->hasMany('id', __NAMESPACE__ . '\Posts', 'user_id', ['alias' => 'Posts']);
              }
          }
         
          //Get user's posts
          $user = Users::findOne(2);
          foreach ($user->getPosts() as $post) {
              echo $post->title;
          }
         
  • public function getRelated(string $alias, array $filters, array $options)

    Get related models.
  • public function getRules(variable $fields)

    Get rules for validation.
    
          // Get rules for one field
          $this->getRules('password');
         
          // Get rules for multiple fields
          $this->getRules(['fullName', 'about']);
         
          // Get all rules
          $this->getRules();
         
  • public function setRules(array $rules, bool $merge)

    Set rules for validation.
  • public function __serialize()

    Serialize the model's data.
  • public function __unserialize(array $serialized)

    Unserialize and set the data.
  • public function __call(string $method, variable $arguments)

    Magic call to get related models.
  • internal function zephir_init_properties_Ice_Mvc_Model()