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.

Difference between Phalcon\Mvc\User\Component. Plugin, and Module?

I'm looking at these below:

http://docs.phalconphp.com/en/latest/api/Phalcon%5Mvc%5User%5Component.html http://docs.phalconphp.com/en/latest/api/Phalcon%5Mvc%5User%5Module.html http://docs.phalconphp.com/en/latest/api/Phalcon%5Mvc%5User%5Plugin.html

1: They all have the same features, and I'm guessing they are just named differently for organization. Is it correct to assume that?

2: Is the purpose of these are to have functionality outside of Models/Controllers that still have access to system services registered in the bootstrap?



3.4k
Accepted
answer

TL;DR - It's only a semantic difference at the moment, but it could change in the future. As far as the difference, this is what I've noticed in the places I've worked:

modules - Self-contained, reusable, collection of classes - including models, views, and controllers - created to perform a certain set of actions. For example, an admin module that has it's own MVC structure that can be used on a variety of projects.

components - An independent class or set of classes designed to extend the base functionality of a framework or application. For instance, I created a locale class for Phalcon that finds the user's best locale based on an array of available locales in the config. I extended Phalcon\DI\Injectable, but I probably should have used Phalcon\Mvc\User\Component. If I add any event logic (perhaps a pre.dispatch listener) I'll change it over.

plugins - Add a limited, specific capability to an existing application or framework component. I'm kinda wondering if Phalcon\Mvc\User\Plugin is really needed as most plugins extend the class it's "plugging into". For instance, if you are making a Phalcon\Tag plugin, you extend that class, not Phalcon\Mvc\User\Plugin (http://docs.phalconphp.com/en/latest/reference/tags.html#tag-service). When I wrote an scrypt hashing plugin, it extended the Phalcon\Security class.

@Phalcon, are you shaping this framework to follow the same lines, or do you have a different philosophy?



81.3k

@Mark yes, those are exactly my thoughts, thanks for your answer

TL;DR - It's only a semantic difference at the moment, but it could change in the future. As far as the difference, this is what I've noticed in the places I've worked:

modules - Self-contained, reusable, collection of classes - including models, views, and controllers - created to perform a certain set of actions. For example, an admin module that has it's own MVC structure that can be used on a variety of projects.

components - An independent class or set of classes designed to extend the base functionality of a framework or application. For instance, I created a locale class for Phalcon that finds the user's best locale based on an array of available locales in the config. I extended Phalcon\DI\Injectable, but I probably should have used Phalcon\Mvc\User\Component. If I add any event logic (perhaps a pre.dispatch listener) I'll change it over.

plugins - Add a limited, specific capability to an existing application or framework component. I'm kinda wondering if Phalcon\Mvc\User\Plugin is really needed as most plugins extend the class it's "plugging into". For instance, if you are making a Phalcon\Tag plugin, you extend that class, not Phalcon\Mvc\User\Plugin (http://docs.phalconphp.com/en/latest/reference/tags.html#tag-service). When I wrote an scrypt hashing plugin, it extended the Phalcon\Security class.

@Phalcon, are you shaping this framework to follow the same lines, or do you have a different philosophy?

Nice, well explained. Btw Im new in phalcon :) thanks for your insights.