About Cascade pick of views

This post is about re-utilizing views, and its best approach to do that.

We have a little framework on top on phalcon , we reutilize it in all our projects (general controller/model function, rapid crud generation, etc), so the the prototyping of an application starts generally with model creation a fast configuration. At this point we have catalogs working and the problem with views starts here.

The excpeted behavior its the framework to have its own views in a views folder inside it, so we can put in a git submodule and easy share it; but when we start the customize phase of each application we put views inside the apps folder (modules) and when volt instantiates (DI) we need to specify wich views-folder to use: the default or the custom one.

The desirable application folder structure

project/
  apps/
    MainModule/
      Models/
      Controllers/
      Views/ <-- The app Views ( first in hierarchy ) 

  Common/ <-- (our framework)
    Controllers/ (rest-json, soap etc)
    Models/
    Views/ <-- all base views (second in hierarchy )

The actual folder structure:

project/
  apps/
    MainModule/
      Models/
      Controllers/


  Common/ <-- (our framework)
    Controllers/ (rest-json, soap etc)
    Models/

  Views/
    Common/
    MainModule/

The problem here is when i create/modify a view that i want to share across projects i have to manually update or make a git-submodule commonViews to share the views. Not too elegant.

Is there any easy-ellegant way to do this or an alternative to this folder structure to get things happen.

any comment or is a too-fool question?

I think one way is that you can use the default views folders in the volt configuration in the index.php, and when you start to create new views you can change the views folder in the initialization of the controllers inside you module.

edited Aug '16

You can cascade views by extending phalcon view class to set two views directories, one is common and other is site specific views folder where in you will have priority to site specific view folder. Idea is first view engine will look into site specfic directory and common directory for templates.