Mvc - Phalcon MVC Examples

Overview

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

You might also like...
Examples of the power of WordPress plugins that will wreck your site.

Examples of the power of WordPress plugins that will wreck your site.

PHP examples - Refactoring by Martin Fowler

Refatoração - segunda edição - Exemplos em PHP https://www.youtube.com/watch?v=TBHehDRuVCs Prefácio: Case de refatoração x entregas e prazos O que é r

SERP Scraping API code examples for Python, PHP and Node.js

SERP Scraping API List of contents Introduction Authentication Google Baidu Bing Yandex Parameters Targets Languages License Introduction With our SER

Some Joomla! 4.x Web Services Api Examples and Experiments to raise the level of awareness of the huge potiental of Joomla! 4.x Web Services.

j4x-api-examples WHY? If you are a Joomla! developer or want to become a Joomla! developer there is a new resource for you The Official New Joomla! Ma

Sitepackage for TYPO3 CMS that adheres to the recommended standards, maps all conceivable functional areas and contains examples for common use cases.

TYPO3 CMS Sitepackage This sitepackage sticks as closely as possible to the recommended standard and maps all conceivable functional areas. There are

 Phalcon Demo Application
Phalcon Demo Application

Phalcon Demo Application We use modified Phalcon INVO Application to demonstrate basics of Codeception testing. We expect to implement as many feature

Phalcon official Forum

Phosphorum 3 Phosphorum is an engine for building flexible, clear and fast forums. You can adapt it to your own needs or improve it if you want. Pleas

Phalcon PHP Meta tags Service

About Phalcon meta tags plugin for PhalconPHP. This plugin allows you to easily and flexibly customize the meta tags of your view. If this plugin help

Implementation of an API application using the Phalcon Framework

phalcon-api Sample API using Phalcon Implementation of an API application using the Phalcon Framework https://phalcon.io Installation Clone the projec

Comments
  • Fatal Error fix

    Fatal Error fix

    fixes an error "Fatal error: Class 'Application' not found in /public/index.php on line 81" caused by Phalcon\Mvc\Application not being included

    opened by Bana0615 1
Owner
The Phalcon PHP Framework
High performance, full-stack PHP framework delivered as a C extension.
The Phalcon PHP Framework
A Phalcon paginator adapter for Phalcon Collections

Phalcon Collection Paginator A Phalcon paginator adapter for Phalcon Collections Why create this? Being familiar with the various Pagination data adap

Angel S. Moreno 2 Oct 7, 2022
This is a Native PHP MVC. If you will build your own PHP project in MVC with router, you can clone this ready to use MVC pattern repo.

Welcome to PHP-Native-MVC-Pattern ?? If you will build your own PHP project in MVC with router, you can clone this ready to use MVC pattern repo. Work

null 2 Jun 6, 2022
YL MVC Structure (PHP MVC) is a pattern made in PHP used to implement user interfaces, data, and controlling logic.

YL MVC Structure (PHP MVC) is a pattern made in PHP used to implement user interfaces, data, and controlling logic. It is built based on the combination of ideas from the Yii framework and Laravel framework (yl).

Tan Nguyen 3 Jan 3, 2023
the examples of head first object oriented analysis & design - in PHP

Head First object oriented analysis & design in (PHP) after cloning the repository, you have to install the project's dependancies by running the foll

Muhammed ElFeqy 3 Oct 16, 2021
Showing what's new in PHP 8 with examples and tests

#PHP 8 what's new with examples Showing what's new in PHP 8 with examples and tests. I believe that reading about the changes is not enough, so grab t

Grzegorz Bielski 1 Dec 14, 2022
Custom code snippets and examples for SkyVerge-built WooCommerce extensions

SkyVerge WooCommerce Plugins Welcome to the wc-plugins-snippets repository! This repository stores code snippets related to SkyVerge WooCommerce plugi

SkyVerge 255 Nov 16, 2022
Demo serverless applications, examples code snippets and resources for PHP

The Serverless LAMP stack Examples Code example Description AWS blog link 0.1-SimplePhpFunction A very simple implementation of a PHP Lambda function.

AWS Samples 303 Dec 20, 2022
Wordpress Plugin Boilerplate but Powered with examples and a generator!

WordPress Plugin Boilerplate Powered WordPress Plugin Boilerplate Powered is a complete foundation for building your WordPress plugins following PSR-4

WordPress Plugin Boilerplate Powered 604 Dec 24, 2022
Design Pattern Examples in PHP

Design Patterns in PHP This repository is part of the Refactoring.Guru project. It contains PHP examples for all classic GoF design patterns. Each pat

Refactoring.Guru 909 Dec 22, 2022
Examples of some common design patterns implemented in php

What is a Design Pattern? Design patterns are typical solutions to common problems in software design. Each pattern is like a blueprint that you can c

Bakhtiyor Bahritidinov 4 Feb 11, 2022