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.

Perform merge between views of two or more modules

I have a Phalcon PHP modular application. I am making an administrative interface to control which modules should be used in the system. One module controls the application's default interface, while the other modules add functionalities.

I have the problem: when another module to enabled, it can add the HTML content to the other interface control module. In this way I would like to merge two or more views. I am using Volt as template engine.

Is this possible in Phalcon?



2.9k

How does the application (currently) know if a module is enabled/disabled?

Through the configuration file config.php, located in the config directory at the root of the application.

return new \Phalcon\Config([
...
    'modules' => [
        'module01',
        'module02',
        ...
        'moduleN',
    ],
...
]);

How does the application (currently) know if a module is enabled/disabled?



2.9k
Accepted
answer
edited Apr '17

Then you'll need to do some logic in your controller (to set a view property) and in your view to check the module is enabled. Something like;

*Controller.php

$this->view->modules_enabled = $this->di->get("config")->modules;

*.volt

Then, in your view, something like (assuming the module is in partials/module01);

{% if module01 in modules_enabled %}
   <div id="module">{{ partial("partials/module01") }}</div>
{% endif %}

Hi H!

Thanks for the excellent answer!



2.9k

No worries. Glad to help! :)

Hi H!

Thanks for the excellent answer!