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

Understanding how phalcon works

Hello Guys;

I'm an experienced PHP programmer that ran out of patience with other frameworks and looking to give Phalcon en try.

This is my main concern, Lets say I have a module "members" and need to have into it another library to handle "wishlist", this library does not necessarily have to be present in each usage of this module, and I also need to be able to check if the person adding info to their wishlist is currently a member of the site, how can this be executed using phalcon?

Thanks in advance...

The term "module" has special meaning in Phalcon - I'm not sure if you meant it that way. If I'm understanding your meaning correctly, you have one model - "Member", and another model "Wishlist" that some Members may have. Please correct me if I'm misunderstanding.

Look into model relationships: https://docs.phalcon.io/en/latest/reference/models.html#relationships-between-models . You can relationships to ensure you are only accessing Wishlists for members.

edited Mar '14

Well, I'm more focus on the scalability of the Members model, and yes, you kind of got it right. The issue comes when I want wishlist to be part of the Members Model without having to create a model for it, and this wishlist does not have to be present in each of the installments.

Basically I want to know of phalcon has a way to have a model within a model, as a module/add-on relationship where the add-on is not mandatory for the module to run. it can be conditional. Bellow is a diagram of the folder tree if that helps:

  root:
   - members:
   -  - wishlist:
   -  -  - model
   -  -  - controler
   -  -  - views
   -  - model
   -  - controlers
   -  - views
   - products:
   -  - categories:
   -  -  - model
   -  -  - controler
   -  -  - views
   -  - model
   -  - controlers
   -  - views

Let me know if this explanation works better...

Thanks in advance.

edited Mar '14

Phalcon lazy loads as much as possible. You can set up your Member-to-Wishlist relationship, and the Wishlist will only be loaded if and when you ask for it.

And while Phalcon is pretty flexible where you store your controllers/models/views, I think they do still all need to be in the same place, so your folder tree should be re-arranged:

  root:
  - models
  - - Members
  - - Wishlist
  - - Products
  - controllers
  - - MembersController
  - - WishlistController
  - - ProductsController
  - views
  - - members/
  - - wishlist/
  - - products/
  - - - controllers

So based on your answer there is no way to have the wishlist MCV into the wishlist folder? That is a very good problem to have in consideration because I have to be able to give the front end developers the whole system and they need to be able to erase the modules/add-ons they wont be using, I'm sure they can do it the way you just proposed but that definitely can leak to issues...

You sure there is no other way to handle it? Is there any other way to tackle this issue? Any recommendation?....

Best regards and thank you very much for your help.

Well I suppose if you use namespaces you can register multiple paths. Putting all your front-end-dev-editable code in one namespace should allow you to put it all in one folder.

Also, "add-on" has no meaning in Phalcon, while "module" does. For the sake of being clear I'd suggest you use proper terminology properly - just so when you say "module" we can be sure you mean "Phalcon Module" rather than maybe "model" or "component".