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

Devtools module features

Hello everybody.

The devtools are great and save me a lot of time when bootstraping/scaffolding my applications and there is also basic module support builtin: You can create a single module application with the hardcoded path and name 'frontend'.

I would like to extend the module functionality since I think it is a very basic and important aspect of Phalcon to easily develop modular applications. I would like to support different parameters and new commands for handling modules, but I want to hear your thoughts on this:

  • How do you think multi module applications should be handled by the devtools?
  • How would you like to have it called from the CLI?
  • Should modules be configurable (directory structure, defining models, services, routes ...) and how should that configuration be done?

As a first step I can think about something like the following:

Create a module application (this almost works out of the box):

phalcon project modules --module-name=myFancyModule

This call would create a project with the MyFancyModule module. --module-name would default to 'frontend' so the existing functionality won't break.

To add a module to an existing multi module application we might use something like (inside the project path):

phalcon add-module myEvenFancierModule

It would also be great if we could somehow define the directory structure of the generated projects since I like the public/private approach:

phalcon project modules --module-name=holyMoly --module-root=private/modules

BTW: Could we make use of the .phalcon directory to store configurations like this?

Please share your thoughts: What do you think?

P.S. I am just experimenting with Yeoman Generators https://github.com/yeoman/yeoman/wiki/Generators which might work hand in hand with the devtools and would make a complex configuration (e.g. services or routes) very comfortable to handle. A Phalcon generator might be a handy extension.

My mind is that devtools are really convenient to bootstrap a new project, really cool to generate your base models, and so on... but once your application is created i think you shouldnt have to use anymore the devtools, at least i wont. In my mind the devtools are before all made to startup your project faster, to create new modules faster (and only if you dont have modified the base generated structure).

I think that making too much with devtools/module and .phalcon would go in the opposite direction of the phalcon mind and would complexify/freeze too much your project. And in the most extrem cases it mays lead in a too much complicated and hard to maintain manually project.

That's my mind, maybe i'm wrong in some point, feel free to discuss !



98.9k

I think that use a configuration file to describe modules would be ok, something like:

phalcon/config:

[main]
modulesDir = app/modules

Then devtools could try to find the config.php for every module under app/modules to know which are the controller, models and views directories. This way the generator can place the code properly.

Note that this structure would not work if the developer use a different structure like:

apps/
   main/
       frontend/
       backend/
   management/
       frontend/
       backend/

@SneakyBobito I understand that the devtools are something that help you to bootstrap an app, but not to change existing projects. So maybe we should just extend the module features to handle the creation of multiple modules?

@Phalcon What do you think about this: To create multiple modules you might type:

phalcon project projectName modules --module-names=frontend,backend,middleware

and the devtools just do what they do now but scaffold the modules according to the names given in the parameter.

Personally I would like to specify a module directory

phalcon project projectName modules --module-names=frontend,backend,middleware --modules-dir=private/modules

but maybe that is a very special wish.

@michaelkrone Yes, I agree about the fact that we can create modules later (but still it needs that you to dont change the structure of your bootstraped app, or as you said to specify in .phalcon (or any other file) how you want to generate your modules)

@SneakyBobito I totally agree to you now: The devtools should be used for creating an initial "blueprint". They should not mess up my current project. There are tools that can handle such things better - that's why I suggested to extend the existing module features. Since Phalcon gives us the freedom to use nearly every directory structure I also see that this feature can be very hard to maintain.

What the devtools should do (without any configuration see my previous post):

  • Create several modules at once
  • Let me define the name of the created modules
  • Maybe: Allow me to specify the directory the created modules live in

This would not be hard to code and a handy extension of the devtools.

I also would add that devtools should be able to generate models even if we are not in a phalcon project.

Last time i did need some models outside of a phalcon project. Then I generated a new phalcon project,, then i generated the models, the i copied/pasted the generated models files in my other non-phalcon project.

This shouldnt be hard to do. Just add some option to the generate models command to specify database connexion (right now it takes it from the config file of the generated application)

That is indeed a good point. From time to time I need this too.



98.9k

I thinks your suggested syntax is ok:

phalcon project projectName modules --module-names=frontend,backend,middleware
phalcon project projectName modules --module-names=frontend,backend,middleware --modules-dir=private/modules

Also store that directory in .phalcon would be great, so we don't need to type it every time :)

OK. I will prepare a pull request on Saturday.

If model creation could be completed by specifying a module this would be fantastic! I just tried, it failed giving me errors:

phalcon-tools/phalcon: line 78: 2123 Bus error: 10 php "$PTOOLSPATH/phalcon.php" $*

Would love to be able to specify that module :)

Anyway, this is my first comment... GREAT JOB SO FAR!!! I'm extremely impressed especially coming from CodeIgniter and ZF. I just tried the css and js minification via the Phalcon\Assets\Manager and it exceeded my expectations.

phalcon project projectName modules --module-names=frontend,backend

The above command returns Error: Unknown parameter module-names

Any solution?



58.4k

You try this

    phalcon project projectName --type=modules 

It will generate module frontend then you clone frontend to backend ...

You can also try

phalcon project ProjectName modules

https://github.com/pokisin/Phalcon-Multiples-modulos-esqueleto