You’re browsing the documentation for v3.x.

  Click here  for earlier leaf mvc versions.

# Leaf MVC

Leaf MVC is a lightweight and minimal MVC wrapper leaf PHP framework that provides a more scalable and powerful setup for creating web apps and APIs quickly and efficiently. Leaf MVC is also heavily inspired by Ruby on rails, laravel and slim, it provides you the best of these packages and avoids the "not so goods"😁

v3.0 packs in a bunch of fresh functionality, and also features added in v3 (opens new window) of the core Leaf package. You can view all these changes here.

Also, the lightweight core framework is not always suitable for every use case, which is another reason a scalable setup in the form of Leaf MVC has been created.

# Why Leaf MVC?

There are a variety of tools and frameworks available to you when building a web application. However, we believe Leaf + MVC is the best choice for building modern, full-stack web applications.

# 📚 Shallow learning curve

Whether you are new to PHP or have prior experience with the language, leaf MVC helps you fit right in. All you need to get started with Leaf MVC is basic PHP knowledge and a little familiarity with MVC concepts. You can learn leaf as you build 🥰

# 🪶 Lightweight

If you have had experience with other MVC frameworks like Laravel, you would notice how simple and straightforward leaf MVC is compared those which need you to learn a whole bunch of their framework specific things. Leaf is light and so is Leaf MVC.

# 💪🏽 Powerful

Leaf MVC packs a ton of powerful tools which speed up your development process by folds. You have simple tools and modules like authentication (opens new window), commands with aloe (opens new window), MVC tools with MVC core (opens new window) and a ton of other modules (opens new window).

# Installation

You can quickly create a leaf MVC project with composer (opens new window).

composer create-project leafs/mvc <project-name> v3.x-dev
1

or with the leaf cli:

leaf create <project-name> --mvc --v3
1

# Directory Structure

This will create a new leaf MVC project named <project-name>. Inside the new directory, you should have a structure like this.

Note

The directory structure has had a refresh. We normalized the folder cases to lowercase. Note that this only applies to the default leaf MVC folders. Custom folders will have to follow the class structure as done in earlier versions.

C:.
├───app
│   ├───console
│   ├───controllers
│   │   └───Auth
│   ├───database
│   │   ├───factories
│   │   ├───migrations
│   │   └───seeds
│   ├───helpers
│   ├───models
│   ├───routes
│   └───views
│       ├───components
│       └───pages
│           └───errors
├───config
│   └───command
├───public
│   └───assets
│       ├───css
│       ├───images
│       ├───js
│       └───sass
├───storage
│   ├───app
│   │   └───public
│   ├───framework
│   │   └───views
│   └───logs
└───vendor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  • app: This is where you will mostly be working. It houses all your controllers, command and db files.
  • config: This holds all your configuration files.
  • lib: You can place your libraries and piece files which you need for your app.
  • storage: Storage for your files, images, text, databases...
  • vendor: This holds all your dependencies and installed files.

In the project root, you can open up your console tool and type in

php leaf serve
1

This will start the php web server and load your project at http://localhost:5500 by default.