We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

questions about OOP and Phalcon

I recently read a book on object-oriented programming: classes, methods, encapsulation, and class relations (Dependency, Association, Aggregation and Composition) of PHP5

my question is?

is feasible to apply the class relations in Phalcon (Dependency, Association, Aggregation and Composition)?

or

ORM is best to use your data loading and go according to their relationships(HasMany,HasOne, HasManyToMany)?



16.4k

It dependes on what you want to do, ORM is just for mapping a table to a object



7.9k
Accepted
answer

I prefer call Model as Repository.

And you may create additional layer for your application in MVC, so your business logic not in Model and/or Controller.

For example for my application I have User class.

namespace App\ExampleApp\Module

use App\Model\UserRepository;

class User
{
    private $repository;

    public function __construct(UserRepository $user_repository)
    {
        $this->repository = $user_repository;
    }

    public function createUser()
    {
        // some logic here
    }

    // some other method here
}

You controller role is only for controlling request and dispatch to your application layer. With this pattern you can archive OOP and SOLID principle.