Cygnite - A Modern Toolkit For Web Developers

The Elegant Way of Building Full-Featured Web Applications

Cygnite Dynamic Routing

Models

Documentation

Models

Introduction

Models are typically stored in the src/Apps/Models/ directory. However, models can live in any directory or subdirectory. Model class must extends "\Cygnite\Database\Cyrus\ActiveRecord". Model are typical class acting as simple orm to map your database tables as objects to receives the information and update it's states. Each table name must be lowercase underscore prefixed and model class name must be StudlyCaps.

Importing Model Class

Model classes are autoloaded by Composer when you create an object of model class. Specify model namespace in controller using use keyword. Create an object of model class and do stuffs.


  namespace Apps/Controllers;

  use Apps/Models/User;

Accessing Model Functions

Sometime you may need to create a model function to modify the object or use filters over data, such scenario create an function in the model class and access using class object. For more details about model filters read Activerecord documentation.


use Apps/Models/User;

$user = new User();
$user->getUsers();

Accessing model directly in view pages is anti pattern, but sometime you want to access to do some stuffs. You can access model data similarly by creating object of the class.

Model class is a wrapper over Cyrus ActiveRecord orm, all features are accessible using model. Read more about database related stuffs on cyrus ActiveRecord, Finders, Schema Builder, Migrations etc. documentation.

That's all small introduction of model class. But there are more stuffs you can do with your simple model class.


Follow Us On Facebook Twitter Google+ Linkedin
Released Under The MIT Public License. Copyrights @2012-2017. Powered by- Sanjoy Dey Productions.