Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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)?



11.1k

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



5.8k
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.