Models
Models control the data source, they are used for collecting and issuing data,
this could be from a remote service as XML,JSON or using a database/ORM to
get and fetch records.
A Model is structured like a controller; it's a class.
You have two choices. Create a custom model that contains your business logic or
if you want to make operations with database, you need to create row and table models.
The 'database' model needs to extend the parent ORM model.
For example, if you want to have a model for 'user' table will need
to create two files: row and table model.
So, you will have the following structure:
App\
Models\
Row\
User.php
Table\
User.php
In App\Models\Row\User.php you need to have something like:
namespace Models\Row; use Core\Orm\RowGateway; class User extends RowGateway { }
In App\Models\Table\User.php you need to have something like:
namespace Models\Table; use Core\Orm\TableGateway; class User extends TableGateway { protected $_name = 'user'; protected $_primary = 'user_id'; protected $_rowClass = 'Models\Row\User'; }
For more information about ORM models, read the section ORM.
If you want to create a custom model, things are much simpler. You will have something like:
namespace Models; class MyModel { public function getName() { return 'Crater PHP Framework'; } }
And in your controller:
public function indexAction() { $myModel = new \Models\MyModel(); echo $myModel->getName(); }↑