PHPackages                             uhi67/umvc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. uhi67/umvc

ActiveLibrary[Framework](/categories/framework)

uhi67/umvc
==========

UMVC simple PHP framework

3.0.2+uhi67(1mo ago)3712[2 issues](https://github.com/uhi67/umvc/issues)[1 PRs](https://github.com/uhi67/umvc/pulls)1MITPHPPHP &gt;=8.2

Since May 11Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/uhi67/umvc)[ Packagist](https://packagist.org/packages/uhi67/umvc)[ Docs](https://umvc.uhisoft.hu/)[ RSS](/packages/uhi67-umvc/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (16)Versions (32)Used By (1)

UMVC framework
==============

[](#umvc-framework)

Version 3.0.2+uhi67 -- 2026-03-18

A simple web-application framework implementing model-view-controller (MVC) architectural pattern.

Key features
------------

[](#key-features)

- simple html/php based views with rendering hierarchy
- PDO-based database connection with array-based query builder (only MySQL is currently implemented)
- easy-to-use Model classes
- simple URL-path to Controller/method translation with automatic parameter passing
- database migration support
- user login via SAML (Using this feature needs `composer require "simplesamlphp/simplesamlphp:^2.2"`)

### Modules

[](#modules)

UMVC supports modules, see configuration/components.

### Codeception support

[](#codeception-support)

The framework supports functional testing with its framework plugin. Globally installed codeception must be compatible with required (currently v3.1.2)

### Command line

[](#command-line)

UMVC supports CLI. You may create your own commands. The built-in commands are:

- migrate
- cache
- create

Run commands as `php app $command/$action $parameters`. Run `php app` to get the list of available commands, including the built-in and the application-defined ones.

Installation
------------

[](#installation)

The framework can be included into your project with composer. Run `composer require uhi67/umvc:dev-master`. New, empty project can be created using `composer create-project --prefer-dist uhi67/umvc-app name`. This will deliver you a new empty application using UMVC framework into the named directory. Choose any name you prefer.

First steps to build your application using UMVC
------------------------------------------------

[](#first-steps-to-build-your-application-using-umvc)

**Warning: This part is under construction.**Learn more about the mentioned classes in the docblock of the class definition.

1. Create `composer.json` of your application, and include `uh67/umvc`, e.g `composer init --name myname/myapp --require uhi67/umvc:*`.
2. Run `composer update`.
3. Copy `vendor/uh67/umvc/app` to your application's root. This is the launcher of the CLI commands.
4. Copy `vendor/uh67/umvc/www/index.php` and `.htaccess` to your application's www directory. This is the router of the web interface.
5. Create your application's config in the `config/config.php` file, see template in `vendor/uh67/umvc/config/config-template.php`.
6. Create a `runtime` directory writable by the webserver to place temporary files.
7. Create the `www/assets` directory writable by the webserver to place cached asset files of various components.

#### Build your application using MVC pattern

[](#build-your-application-using-mvc-pattern)

1. Create your controllers in the `controllers` dir, using `\app\controllers` namespace, and derive them from `uhi67\umvc\Controller`.
2. Create the views in the `views` dir, in simple PHTML format, and organize them according to `views/controller/action.php` structure.
3. Create your models in the `models` directory. Database models are `\uhi67\umvc\Model`, database-less models are `\uhi67\umvc\BaseModel`.

#### Other basic principles

[](#other-basic-principles)

1. Migrations are for versioning and recording database changes in source code. Place migration steps into `migrations` directory.
2. Layout is a special view to embed all other views within. Place layouts in `views/layouts` directory. Views can call other partial views.
3. You can define CLI commands in `commands` directory, deriving from `\uhi67\umvc\Command` class. There are some built-in command in the framework. `php app` command lists all available commands, both built-in and custom ones.
4. A simple file-based localization support is built-in. Place your translations into `messges/la.php` files where "la" is the language you want to translate to.

#### Component configurations and properties

[](#component-configurations-and-properties)

All components,most of UMVC classes, including the main App class itself, is a `\uhi67\umvc\Component`. `Component` implements **property** features: magic getter and setter uses getProperty and setProperty methods. `Component` is **configurable**: constructor accepts a configuration array containing values for public properties.

#### Built-in components

[](#built-in-components)

1. `MySqlConnection` -- to connect to database. Includes SQL query builder. Currently the only implementation of `Connection`.
2. `FileCache` -- the only implementation of `CacheInterface`.
3. `SamlAuth` -- the only implementation for `AuthManager`.
4. `L10n` -- simple localization, default auto-included, translates UMVC messages only.
5. `L10nFile` -- the file-based localization to translate messages of your application.

#### Other basic classes you can use

[](#other-basic-classes-you-can-use)

1. `Form` -- a widget with built-in view to display and process HTML forms using your Models.
2. `Grid` (widget, but the built-in view is still missing) -- to display paginated, filtered lists of Models.
3. `Query` -- Represents a parametrized and flexible SQL query in php structure. SQL command can be built from it.
4. `Request` -- Represents the HTTP request, can be used to fetch GET and POST parameters.
5. `Session` -- Represents the current PHP session, can be used to get and set variables.

#### Entry scripts, URLs and routing

[](#entry-scripts-urls-and-routing)

The single entry script for the web application is the `www/index.php`. Respectively, the single entry script for the CLI application is the `app` file. Both of them must be copied into your application directory from the `vendor/uhi67/umvc/` directory.

The `www/.htaccess` rules redirect all not-found requests to the `www/index.php`. However, static assets are served directly from the www directory. Learn more about serving library assets later.

The `index.php` initializes the autoloader, load the main configuration, creates the main object (class defined in the configuration, usually `uhi67/umvc/App` or its descendant). The main configuration follows the rules of the configurable `Component`.

##### Routing

[](#routing)

All URL formed as  is processed the following way:

`uhi67/umvc/App` parses the request, computes the actual controller class (derived from `uhi67/umvc/Controller`) to use, creates the controller and runs the requested action method. As in the example above, **acontroller** refers to your controller class in your `controllers` directory as *AcontrollerController*, and **anaction** refers to the action method (as *actionAnaction*).

If the action name is missing from the URL, the `actionDefault` will be run. If the controller name is missing as well, the configured *mainController* will be used. It is also possible to create a URL with an action name of the default controller without specifying the controller name - the only restriction you cannot have a controller with the same name as this action.

Al CLI command formed as `php app acontroller/anaction` is processed the following way:

`uhi67/umvc/App` parses the request, computes the actual controller class (derived from `uhi67/umvc/Command`) to use, creates the controller and runs the requested action method. As in the example above, **acontroller** refers to your controller class in your `commands` directory as *AcontrollerController*, and **anaction** refers to the action method (as *actionAnaction*). Built-in commands can be run the same way. A command with the same name in our application overrides the built-in command.

##### using URLs in your controller action

[](#using-urls-in-your-controller-action)

The parts of the current URL request can be accessed as:

- path: the path portion passed to the controller (controller name already shifted out)
- query: the query part of the original request, as an associative array

To create a new URL using controller and action names, and optioanl qurey parameters, use one of the following:

- $this-&gt;app-&gt;createUrl(\['controller/action', 'key'=&gt;'queryvalue', ..., '#'=&gt;'fragment'\]) -- all parts are optional
- return $this-&gt;app-&gt;redirect(\[...\]) -- to terminate the action with a redirection

#### Serving library assets

[](#serving-library-assets)

In your view files, you can refer your static assets located under `www` directory in static way, e.g ``. On the contrary, if you want to refer to an asset file located somewhere in the composer-created vendor library, you can use them this way:

- `
