PHPackages                             amostajo/lightweight-mvc - 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. amostajo/lightweight-mvc

ActiveLibrary[Framework](/categories/framework)

amostajo/lightweight-mvc
========================

A light weight (small) MVC framework for Wordpress plugins and themes.

v1.0.5(10y ago)1392661MITPHPPHP &gt;=5.4.0

Since Jul 20Pushed 9y ago4 watchersCompare

[ Source](https://github.com/amostajo/lightweight-mvc)[ Packagist](https://packagist.org/packages/amostajo/lightweight-mvc)[ RSS](/packages/amostajo-lightweight-mvc/feed)WikiDiscussions v1.0 Synced 1mo ago

READMEChangelog (5)DependenciesVersions (9)Used By (1)

LIGHTWEIGHT MVC (For Wordpress plugins and themes)
==================================================

[](#lightweight-mvc-for-wordpress-plugins-and-themes)

---

[![Latest Stable Version](https://camo.githubusercontent.com/d83bd4e1b28929f0a3fccd074a7b20557bd08ba7334688b5c9789be64673146e/68747470733a2f2f706f7365722e707567782e6f72672f616d6f7374616a6f2f6c696768747765696768742d6d76632f762f737461626c65)](https://packagist.org/packages/amostajo/lightweight-mvc)[![Total Downloads](https://camo.githubusercontent.com/67f57c6e9b4643fadd3e93ad00f67a82552bfa68f4b555c41328c0160ea30934/68747470733a2f2f706f7365722e707567782e6f72672f616d6f7374616a6f2f6c696768747765696768742d6d76632f646f776e6c6f616473)](https://packagist.org/packages/amostajo/lightweight-mvc)[![License](https://camo.githubusercontent.com/2d0188a62e5e33e66da4f29e6e20188208aed1a8ac9cdf44a8f2756e0d5ff384/68747470733a2f2f706f7365722e707567782e6f72672f616d6f7374616a6f2f6c696768747765696768742d6d76632f6c6963656e7365)](https://packagist.org/packages/amostajo/lightweight-mvc)

**Lightweight MVC** is a small framework that adds *Models*, *Views* and *Controllers* to your custom **Wordpress** plugin or theme.

Lightweight MVC utilices existing Wordpress functionality preventing from overloading the already heavy loaded Wordpress core.

This framework was inspired by **Laravel** to add the MVC design pattern to Wordpress development in an efficient, elegant and optimized way.

- [Requirements](#requirements)
- [Installation](#configuration)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Models](#models)
        - [Aliases](#aliases)
        - [Types](#types)
    - [Views](#views)
    - [Controllers](#controllers)
    - [Engine](#engine)
    - [Helpers](#helpers)
- [Coding Guidelines](#coding-guidelines)
- [License](#license)

Requirements
------------

[](#requirements)

- PHP &gt;= 5.4.0

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

[](#installation)

Add

```
"amostajo/lightweight-mvc": "1.0.*"
```

to your composer.json. Then run `composer install` or `composer update`.

**NOTE** If you are not using composer, you can download the ZIP but will need to include the files manually since not autoload will be generated.

Configuration
-------------

[](#configuration)

Your project needs to store somewhere your `Models`, `Views` and `Controllers`, and **Lightweight MVC** must know where.

Create these as folders, like this:

```
[PROJECT ROOT]
 |---> [controllers]
 |---> [models]
 |---> [views]
```

Then in your `functions.php` or `plugins.php` file set these at the very beginnning, like:

```
// Path to the controllers folder.
$engine = new Amostajo\LightweightMVC\Engine(

	// Path to the views folder.
	$views_path = 'path_to_views_folder',

	// Path to the controllers folder.
	$controllers_path = 'path_to_controllers_folder',

	// Namespace of your plugin or theme. For controller access
	$namespace = 'MyApp'
);
```

Usage
-----

[](#usage)

### Models

[](#models)

In **Lightweight MVC**, a `Model` at the end is just a type of Wordpress post. Store your models at the `models` folder.

Here is model example:

```
