These are examples of MVC file structures you can employ using Phalcon >= 2.0.x
This is a very simple MVC structure, it contains one model, two controllers and a view. This example does not implement namespaces. Services are defined in public/index.php without using Di\FactoryDefault:
simple
βββ apps
βΒ Β βββ controllers
βΒ Β βΒ Β βββ IndexController.php
βΒ Β βΒ Β βββ ProductsController.php
βΒ Β βββ models
βΒ Β βΒ Β βββ Products.php
βΒ Β βββ views
βΒ Β βββ products
βΒ Β βββ index.phtml
βββ public
βββ index.php
This is a very simple MVC structure, it contains one model, two controllers and a view. This example does not implement namespaces. Services are defined in public/index.php without using Di\FactoryDefault. This example uses Volt as template engine:
simple-volt/
βββ app
βΒ Β βββ config
βΒ Β βΒ Β βββ config.php
βΒ Β βΒ Β βββ loader.php
βΒ Β βΒ Β βββ services.php
βΒ Β βββ controllers
βΒ Β βΒ Β βββ ControllerBase.php
βΒ Β βΒ Β βββ IndexController.php
βΒ Β βββ views
βΒ Β βββ index
βΒ Β βΒ Β βββ index.volt
βΒ Β βΒ Β βββ test.volt
βΒ Β βββ index.volt
βΒ Β βββ layouts
βΒ Β βββ template.volt
βββ index.html
βββ public
βββ index.php
Another very simple MVC structure, it contains one model, three controllers and a view. Routes are defined in app/config/routes.php. Some routes point to controllers in a subdirectory of controllers/:
simple-subcontrollers/
βββ app
βΒ Β βββ config
βΒ Β βΒ Β βββ config.php
βΒ Β βΒ Β βββ loader.php
βΒ Β βΒ Β βββ routes.php
βΒ Β βΒ Β βββ services.php
βΒ Β βββ controllers
βΒ Β βΒ Β βββ ControllerBase.php
βΒ Β βΒ Β βββ UsersController.php
βΒ Β βΒ Β βββ admin
βΒ Β βΒ Β βββ ControllerBase.php
βΒ Β βΒ Β βββ UsersController.php
βΒ Β βββ views
βΒ Β βββ admin
βΒ Β βΒ Β βββ users
βΒ Β βΒ Β βββ index.volt
βΒ Β βββ index
βΒ Β βΒ Β βββ index.volt
βΒ Β βββ index.volt
βΒ Β βββ users
βΒ Β βββ index.volt
βββ index.html
βββ public
βββ index.php
Simple MVC structure without employing Phalcon\Mvc\Application. This application does not use namespaces. This is an example of how you can override Phalcon\Mvc\Application by implementing a similar functionality. It also defines services without using Di\FactoryDefault in public/index.php:
simple-without-application/
βββ apps
βΒ Β βββ controllers
βΒ Β βΒ Β βββ IndexController.php
βΒ Β βΒ Β βββ ProductsController.php
βΒ Β βββ models
βΒ Β βΒ Β βββ Products.php
βΒ Β βββ views
βΒ Β βββ products
βΒ Β βββ index.phtml
βββ public
βββ index.php
This a single-module MVC structure without namespaces. You can find the module's directories under the apps/ directory. This example does not use namespaces. All services are initialized in public/index.php. Also, in this file, you can also find an application class that initializes services and autoloaders grouping these tasks by methods.
single
βββ apps
βΒ Β βββ controllers
βΒ Β βΒ Β βββ IndexController.php
βΒ Β βΒ Β βββ ProductsController.php
βΒ Β βββ models
βΒ Β βΒ Β βββ Products.php
βΒ Β βββ views
βΒ Β βββ index.phtml
βΒ Β βββ products
βΒ Β βββ index.phtml
βΒ Β βββ test.phtml
βββ public
βββ index.php
This a single-module MVC structure using namespaces. You can find the module's directories under the apps/ directory. This example does not use namespaces. All services are initialized in public/index.php. Also, in this file, you can also find an application class that initializes services and autoloaders grouping these tasks by methods.
single-namespaces/
βββ apps
βΒ Β βββ controllers
βΒ Β βΒ Β βββ IndexController.php
βΒ Β βΒ Β βββ ProductsController.php
βΒ Β βββ models
βΒ Β βΒ Β βββ Products.php
βΒ Β βββ views
βΒ Β βββ products
βΒ Β βββ index.phtml
βββ public
βββ index.php
A single-module MVC structure as is generated by Phalcon-Devtools. Instead of initialize every service individually, it uses Di\FactoryDefault:
single-factory-default/
βββ app
βΒ Β βββ config
βΒ Β βΒ Β βββ config.php
βΒ Β βββ controllers
βΒ Β βΒ Β βββ ControllerBase.php
βΒ Β βΒ Β βββ IndexController.php
βΒ Β βΒ Β βββ TestController.php
βΒ Β βββ views
βΒ Β βββ index
βΒ Β βΒ Β βββ index.phtml
βΒ Β βββ index.phtml
βββ index.html
βββ public
βββ index.php
This a single-module MVC structure. All files and directories are camelized (including views):
single-camelized-dirs/
βββ App
βΒ Β βββ Config
βΒ Β βΒ Β βββ Loader.php
βΒ Β βΒ Β βββ Services.php
βΒ Β βββ Controllers
βΒ Β βΒ Β βββ IndexController.php
βΒ Β βΒ Β βββ ProductsController.php
βΒ Β βββ Models
βΒ Β βΒ Β βββ Products.php
βΒ Β βββ Views
βΒ Β βββ Index
βΒ Β βΒ Β βββ Index.phtml
βΒ Β βββ Products
βΒ Β βββ Index.phtml
βββ public
βββ index.php
This a multi-module MVC structure. This example implements two modules: frontend and backend. By default frontend is served if no route to backend is asked. You can define which routes use one module or another in public/index.php:
multiple/
βββ apps
βΒ Β βββ backend
βΒ Β βΒ Β βββ Module.php
βΒ Β βΒ Β βββ controllers
βΒ Β βΒ Β βΒ Β βββ IndexController.php
βΒ Β βΒ Β βΒ Β βββ LoginController.php
βΒ Β βΒ Β βΒ Β βββ ProductsController.php
βΒ Β βΒ Β βββ models
βΒ Β βΒ Β βΒ Β βββ Products.php
βΒ Β βΒ Β βββ views
βΒ Β βΒ Β βββ login
βΒ Β βΒ Β βΒ Β βββ index.phtml
βΒ Β βΒ Β βββ products
βΒ Β βΒ Β βββ index.phtml
βΒ Β βββ frontend
βΒ Β βΒ Β βββ Module.php
βΒ Β βΒ Β βββ controllers
βΒ Β βΒ Β βΒ Β βββ IndexController.php
βΒ Β βΒ Β βΒ Β βββ ProductsController.php
βΒ Β βΒ Β βΒ Β βββ UsersController.php
βΒ Β βΒ Β βββ models
βΒ Β βΒ Β βΒ Β βββ Products.php
βΒ Β βΒ Β βββ views
βΒ Β βΒ Β βββ products
βΒ Β βΒ Β βββ index.phtml
βββ public
βββ index.php
This a multi-module MVC structure. This example implements two modules: frontend and backend. By default frontend is served if no route to backend is asked. You can define which routes use one module or another in public/index.php. Volt is used as template engine:
multiple-volt/
βββ apps
βΒ Β βββ frontend
βΒ Β βββ Module.php
βΒ Β βββ config
βΒ Β βΒ Β βββ config.php
βΒ Β βββ controllers
βΒ Β βΒ Β βββ ControllerBase.php
βΒ Β βΒ Β βββ IndexController.php
βΒ Β βββ views
βΒ Β βββ index
βΒ Β βΒ Β βββ index.volt
βΒ Β βββ index.volt
βββ config
βΒ Β βββ modules.php
βΒ Β βββ services.php
βββ index.html
βββ public
βββ index.php
This a multi-module MVC structure with a common views directory:
multiple-shared-views/
βββ apps
βΒ Β βββ common
βΒ Β βΒ Β βββ views
βΒ Β βΒ Β βββ index
βΒ Β βΒ Β βΒ Β βββ index.phtml
βΒ Β βΒ Β βββ index.phtml
βΒ Β βΒ Β βββ products
βΒ Β βΒ Β βββ index.phtml
βΒ Β βββ modules
βΒ Β βββ backend
βΒ Β βΒ Β βββ Module.php
βΒ Β βΒ Β βββ controllers
βΒ Β βΒ Β βΒ Β βββ IndexController.php
βΒ Β βΒ Β βΒ Β βββ ProductsController.php
βΒ Β βΒ Β βββ models
βΒ Β βΒ Β βββ Products.php
βΒ Β βββ frontend
βΒ Β βββ Module.php
βΒ Β βββ controllers
βΒ Β βββ IndexController.php
βββ public
βββ index.php
This a multi-module MVC structure as is generated by Phalcon-Devtools:
multiple-factory-default/
βββ apps
βΒ Β βββ frontend
βΒ Β βββ Module.php
βΒ Β βββ config
βΒ Β βΒ Β βββ config.php
βΒ Β βββ controllers
βΒ Β βΒ Β βββ ControllerBase.php
βΒ Β βΒ Β βββ IndexController.php
βΒ Β βββ views
βΒ Β βββ index
βΒ Β βΒ Β βββ index.phtml
βΒ Β βββ index.phtml
βββ index.html
βββ public
βββ index.ph
This a multi-module MVC structure with model service layer pattern implemented:
multiple-service-layer-model/
βββ apps
βΒ Β βββ config
βΒ Β βΒ Β βββ config.php
βΒ Β βΒ Β βββ modules.php
βΒ Β βΒ Β βββ services.php
βΒ Β βββ models
βΒ Β βΒ Β βββ entities
βΒ Β βΒ Β βΒ Β βββ User.php
βΒ Β βΒ Β βββ repositories
βΒ Β βΒ Β βΒ Β βββ Exceptions
βΒ Β βΒ Β βΒ Β βΒ Β βββ InvalidRepositoryException.php
βΒ Β βΒ Β βΒ Β βββ Repositories.php
βΒ Β βΒ Β βΒ Β βββ Repository
βΒ Β βΒ Β βΒ Β βββ User.php
βΒ Β βΒ Β βββ services
βΒ Β βΒ Β βββ Exceptions
βΒ Β βΒ Β βΒ Β βββ InvalidServiceException.php
βΒ Β βΒ Β βββ Service
βΒ Β βΒ Β βΒ Β βββ User.php
βΒ Β βΒ Β βββ Services.php
βΒ Β βββ modules
βΒ Β βββ frontend
βΒ Β βββ Module.php
βΒ Β βββ controllers
βΒ Β βΒ Β βββ ControllerBase.php
βΒ Β βΒ Β βββ IndexController.php
βΒ Β βββ views
βΒ Β βββ index
βΒ Β βΒ Β βββ index.phtml
βΒ Β βββ index.phtml
βββ database.sql
βββ index.html
βββ public
βΒ Β βββ index.php
βββ tests
βββ Services
βΒ Β βββ UserServiceTest.php
βββ TestHelper.php
βββ UnitTestCase.php
βββ phpunit.xm
A micro-framework-like application:
micro
βββ index.php
A micro-framework-like application as is generated by Phalcon-Devtools:
micro-factory-default/
βββ config
βΒ Β βββ config.php
βββ index.html
βββ public
βΒ Β βββ index.php
βββ views
βββ 404.phtml
βββ index.phtml
A micro-framework-like application where views are rendered using Phalcon\Mvc\View\Simple:
micro-simple-views
βββ config
βΒ Β βββ config.php
βΒ Β βββ services.php
βββ index.php
βββ views
βββ 404.volt
βββ 500.volt
βββ index.volt