PHPackages                             mmi/mmi - 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. mmi/mmi

ActiveLibrary[Framework](/categories/framework)

mmi/mmi
=======

MMi Framework Library

5.0.0(1mo ago)629.3k↓27.5%6[2 PRs](https://github.com/milejko/mmi/pulls)5MITPHPPHP &gt;=8.1.0CI passing

Since Sep 19Pushed 1mo ago7 watchersCompare

[ Source](https://github.com/milejko/mmi)[ Packagist](https://packagist.org/packages/mmi/mmi)[ RSS](/packages/mmi-mmi/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (13)Versions (404)Used By (5)

MMi Framework — Developer Guidebook
===================================

[](#mmi-framework--developer-guidebook)

MMi is a PHP full-stack web framework built for speed and flexibility. It supports everything from personal blogs to high-traffic applications and follows an MVC architecture with a DI-container core, a fluent ORM, a form builder, and a rich set of standalone utilities.

- **GitHub**:
- **License**: New BSD License
- **PHP**: ≥ 8.1

---

Table of Contents
-----------------

[](#table-of-contents)

1. [Installation](#installation)
2. [Project Structure](#project-structure)
3. [Configuration (.env)](#configuration-env)
4. [Dependency Injection &amp; Application Bootstrap](#dependency-injection--application-bootstrap)
5. [MVC — Controllers, Views &amp; Routing](#mvc--controllers-views--routing)
6. [ORM](#orm)
7. [Database Layer (Db)](#database-layer-db)
8. [Forms](#forms)
9. [Validators](#validators)
10. [Filters](#filters)
11. [Cache](#cache)
12. [Session](#session)
13. [Security — Auth &amp; ACL](#security--auth--acl)
14. [Translate / i18n](#translate--i18n)
15. [Event Manager](#event-manager)
16. [HTTP — Request &amp; Response](#http--request--response)
17. [Image Processing](#image-processing)
18. [Paginator](#paginator)
19. [Navigation](#navigation)
20. [LDAP](#ldap)
21. [Logging](#logging)
22. [CLI Commands](#cli-commands)
23. [Core Utilities](#core-utilities)
24. [Quality Tooling](#quality-tooling)

---

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

[](#installation)

### Via Composer

[](#via-composer)

```
composer require mmi/mmi
```

Or use the ready-made starter:

```
composer create-project mmi/mmi-standard my-project
```

### Development environment with Docker

[](#development-environment-with-docker)

A `Dockerfile` is included in the repository root for containerised development.

---

Project Structure
-----------------

[](#project-structure)

```
├── src/
│   └── Mmi/               # Framework source
│       ├── App/           # Bootstrap & DI wiring
│       ├── Cache/         # Cache subsystem
│       ├── Command/       # CLI commands
│       ├── Db/            # PDO database adapter
│       ├── EventManager/  # Event dispatcher
│       ├── Filter/        # Value filters
│       ├── Form/          # Form builder
│       ├── Http/          # Request / Response
│       ├── Image/         # GD image helpers
│       ├── Ldap/          # LDAP client
│       ├── Log/           # Logger config
│       ├── Mvc/           # Controller, View, Router
│       ├── Navigation/    # Tree navigation & breadcrumbs
│       ├── Orm/           # Active-record ORM
│       ├── Paginator/     # Pagination helper
│       ├── Resource/      # Templates, i18n files, SQL incrementals
│       ├── Security/      # Auth & ACL
│       ├── Session/       # Session wrapper
│       ├── Translate/     # i18n translator
│       └── Validator/     # Value validators
├── tests/                 # PHPUnit test suite
├── var/cache/             # Compiled DI container & view templates
├── web/                   # Public document root
└── .env                   # Local configuration (gitignored)

```

---

Configuration (.env)
--------------------

[](#configuration-env)

Copy `.env.sample` to `.env` (and optionally `.env.local` for machine-local overrides) and fill in the values. Both files are loaded automatically at bootstrap.

```
# Application
APP_DEBUG_ENABLED=true
APP_VIEW_CDN=https://cdn.example.com
APP_COMPILE_PATH=/var/www/var/cache
APP_TIME_ZONE=Europe/Warsaw

# Cache
CACHE_SYSTEM_ENABLED=true
CACHE_PUBLIC_ENABLED=true
CACHE_PUBLIC_HANDLER=file          # file | redis
CACHE_PUBLIC_PATH=/tmp/mmi-cache
CACHE_PUBLIC_DISTRIBUTED=false

# Database
DB_HOST=127.0.0.1
DB_USER=app
DB_NAME=app
DB_PASSWORD=secret

# Logging
LOG_HANDLER=syslog                 # syslog | stream | console | gelf | slack

# Session
SESSION_COOKIE_HTTP=true
SESSION_COOKIE_SECURE=true
SESSION_HANDLER=files              # files | redis
SESSION_NAME=mmi
SESSION_PATH=/tmp/mmi-sessions
```

---

Dependency Injection &amp; Application Bootstrap
------------------------------------------------

[](#dependency-injection--application-bootstrap)

MMi uses **PHP-DI** as its DI container. The container is compiled and cached for production performance. APCu is used as an additional definition cache when available.

### Web application

[](#web-application)

```
define('BASE_PATH', dirname(__DIR__));
require BASE_PATH . '/vendor/autoload.php';

(new \Mmi\App\App())->run();
```

### CLI application

[](#cli-application)

```
define('BASE_PATH', dirname(__DIR__));
require BASE_PATH . '/vendor/autoload.php';

(new \Mmi\App\AppCli())->run();
```

### DI configuration files

[](#di-configuration-files)

Each module (including your own) can expose a `di.*.php` file returning a PHP-DI definition array. The framework auto-discovers all such files from the application structure and merges them (application definitions take precedence over vendor ones).

```
// src/MyModule/di.mymodule.php
use function DI\autowire;
use function DI\get;

return [
    MyService::class => autowire()
        ->constructorParameter('config', get('my.config.key')),
    'my.config.key'  => 'some-value',
];
```

### Accessing the container

[](#accessing-the-container)

```
// Inside a controller or service that receives ContainerInterface via constructor injection
$service = $container->get(MyService::class);

// Legacy static access (deprecated, avoid in new code)
$service = \Mmi\App\AppAbstract::$di->get(MyService::class);
```

---

MVC — Controllers, Views &amp; Routing
--------------------------------------

[](#mvc--controllers-views--routing)

### Controllers

[](#controllers)

Controllers extend `\Mmi\Mvc\Controller`. Action methods are plain public methods whose names end with `Action`.

```
namespace MyModule\Controller;

use Mmi\Mvc\Controller;

class BlogController extends Controller
{
    // Called after __construct — use instead of overriding constructor
    public function init(): void
    {
        // runs before every action in this controller
    }

    public function indexAction(): void
    {
        // assign variables to the view
        $this->view->posts = $this->fetchPosts();
    }

    public function showAction(): void
    {
        $id = (int) $this->getRequest()->id;
        $this->view->post = (new PostQuery())->whereId()->equals($id)->findOne();
    }

    public function ajaxAction(): void
    {
        // disable the layout wrapper — useful for AJAX / API actions
        $this->view->setLayoutDisabled();
        $this->getResponse()->setTypeJson();
        $this->view->data = ['ok' => true];
    }
}
```

### Views (templates)

[](#views-templates)

Templates are `.tpl` files stored under `src//Resource/template///.tpl`. They are compiled to plain PHP and cached for performance.

```

```

Inside templates `$this` is the `View` object. Useful methods:

MethodDescription`$this->_($key, $params)`Translate a key`$this->escape($value)`HTML-escape a string`$this->url($params)`Build a URL from route params`$this->widget($module, $controller, $action, $params)`Render a sub-widget inline`$this->navigation()`Access the navigation helper`$this->setPlaceholder($name, $content)`Store content for the layout`$this->getPlaceholder($name)`Read a placeholder in the layout`$this->setLayoutDisabled()`Skip the layout wrapper### Layouts

[](#layouts)

The framework looks for a layout template in this order:

1. `//layout.tpl`
2. `/layout.tpl`
3. `app/layout.tpl`

### Routing

[](#routing)

Routes are defined in a `RouterConfig` object and registered via DI:

```
// di.mymodule.php
use Mmi\Mvc\RouterConfig;
use Mmi\Mvc\RouterConfigRoute;

return [
    RouterConfig::class => \DI\decorate(function (RouterConfig $config) {
        $config->addRoute(
            (new RouterConfigRoute())
                ->setPattern('blog/[id:\d+]')
                ->setDefault(['module' => 'blog', 'controller' => 'blog', 'action' => 'show'])
        );
        return $config;
    }),
];
```

Generating URLs:

```
// In a controller
$url = $this->view->url(['module' => 'blog', 'controller' => 'blog', 'action' => 'show', 'id' => 42]);
// → /blog/42

// Directly via the router
$router = $container->get(\Mmi\Mvc\Router::class);
$url = $router->encodeUrl(['module' => 'blog', 'action' => 'show', 'id' => 42]);
```

### Messenger (flash messages)

[](#messenger-flash-messages)

```
// In a controller
$this->getMessenger()->addMessage('Record saved.', 'success');
$this->getResponse()->redirectToUrl($this->view->url([...]));

// In a template
