Book Image

Learning Phalcon PHP

Book Image

Learning Phalcon PHP

Overview of this book

Table of Contents (17 chapters)
Learning Phalcon PHP
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Models


Now that we have the user architecture, before we continue with the rest of the database, let's create the models and a simple CLI task to register a new user.

If you have already installed the Phalcon Developer Tools, you can use them to generate models, or you can manually create them. You can also find them in the source code for this chapter.

Tip

Using the model generator will not create relations between tables. You have to manually create them.

All our models will extend the Base models created in the previous chapter. Next, I will show you a few lines of code containing the important parts of the models, excluding the getters, setters, and protected variables.

The User model

The User model will be located under the App\Core\Models namespace in the apps/Core/Models/ directory:

<?php
namespace App\Core\Models;

class User extends Base {
  public static function find($parameters = array()) {
    return parent::find($parameters);
  }

  public static function findFirst($parameters...