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

Setting up and loading Phalcon modules via composer

Hi,

I've been working with Phalcon 3 (and previously Phalcon 2) for a while now and really like it as a framework.

I'm starting a new project which will comprise of both a MVC and Micro implementation but have a lot of shared code (eg models, libraries, etc) so looking to create composer libraries for each module so they can be independent.
I have a parent repository for both MVC and Micro which would require these packages.

However, I haven't quite worked out how that would work in regards to controllers and/or views for each.

At the moment I've been looking to set up something along the lines of the following:

  • config/
  • library/
  • models/
  • Module.php

Would I be best to put all controllers and views in here as well?
For the MVC part that works with no issue, but how could I incorporate the Micro framework? The Module.php file has the DI setting up the view component which isn't needed by it but it does set up the db component which would be needed by both MVC and Micro.

I guess what I'm asking is, is there a way of setting this kind of project up?

Thanks,
Gary

edited Sep '16

Why you need both micro and mvc ? Just stick only to mvc imho :) Just create something like api module which will return only json and that's it.

I guess for now I can keep working on the MVC part and figure out the micro later.
The reason for both is that one is the web UI and the other is an API which was stripped down as much as possible so it processed less on each request.
I'll see if I can figure that out later then.

So only performance ? To be honest i wouldn't care about it if i was you. Well i myself im putting controllers and views which are used for certain module to Module directory too. Well models therotically should be outside of modules - because i just guess you will use models certain models across modules, so you will still need to register models before dispatching to certain modules. Some for library - if you will want to use some library class in other module - you need obviously register it too in loader.

Obviously composer is building loader for all the things so i guess it won't be a problem.

Check:

https://github.com/drupal-composer/drupal-project

Composer move directories to modules, themes, core.

3