These are examples of MVC file structures you can employ using Phalcon >= 3.0.x
For further documentation, check out the Phalcon Docs.
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 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 Developer Tools.
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 single-module MVC structure which shows a non-standard way of registering services:
single-service-provider/
âââ app
â  âââ Bootstrap.php
â  âââ Http
â  â  âââ Controllers
â  â  â  âââ Controller.php
â  â  â  âââ IndexController.php
â  â  âââ routes.php
â  âââ Models
â  âââ Providers
â  âââ AbstractServiceProvider.php
â  âââ ConfigServiceProvider.php
â  âââ DatabaseServiceProvider.php
â  âââ EscaperServiceProvider.php
â  âââ EventManagerServiceProvider.php
â  âââ ModelsMetadataServiceProvider.php
â  âââ MvcDispatcherServiceProvider.php
â  âââ PhpTemplateEngineServiceProvider.php
â  âââ ResponseServiceProvider.php
â  âââ RouterServiceProvider.php
â  âââ ServiceProviderInterface.php
â  âââ SessionServiceProvider.php
â  âââ TagServiceProvider.php
â  âââ UrlResolverServiceProvider.php
â  âââ ViewServiceProvider.php
â  âââ VoltTemplateEngineServiceProvider.php
âââ bootstrap
â  âââ autoload.php
âââ config
â  âââ application.php
â  âââ providers.php
âââ index.html
âââ public
â  âââ index.php
âââ resources
â  âââ views
â  âââ index
â  â  âââ index.volt
â  âââ index.volt
â  âââ partials
â  âââ content.volt
âââ storage
âââ cache
â  âââ data
â  âââ volt
âââ logs
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
â  âââ 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. 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 Developer Tools:
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.xml
A micro-framework-like application:
micro
âââ index.php
A micro-framework-like application as is generated by Phalcon Developer Tools:
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
Phalcon MVC Examples is open source software licensed under the New BSD License.
See the LICENSE.txt file for more.
Copyright (c) 2011-2016, Phalcon Framework Team