Skip to content

Bana0615/mvc

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

94 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Phalcon MVC Examples

These are examples of MVC file structures you can employ using Phalcon >= 3.0.x

For further documentation, check out the Phalcon Docs.

Simple

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

Simple-Volt

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

Simple-Subcontrollers

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-Without-Application

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

Single

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

Single-Namespaces

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

Single-Factory-Default

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

Single-Camelized-Dirs

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

Single-Service-Provider

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

Multiple

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

Multiple-Volt

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

Multiple-Shared-Views

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

Multiple-Factory-Default

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

Multiple-Service-Layer-Model

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

Micro

A micro-framework-like application:

micro
└── index.php

Micro-Factory-Default

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

Micro-Simple-Views

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

License

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

About

Phalcon MVC Examples

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 88.6%
  • ApacheConf 5.5%
  • HTML 3.2%
  • Volt 2.7%