Skip to content

Usage With Leaf PHP

Leaf PHP is a PHP framework that helps you craft clean, simple but powerful web applications and APIs quickly and easily. Leaf UI can be easily integrated with Leaf PHP to create beautiful, interactive and responsive web applications.

This guide will walk you through the process of integrating Leaf UI with Leaf PHP.

Creating your Leaf PHP project

To quickly get started with Leaf, you can use the Leaf CLI to generate a new project. You can check the Leaf installation docs for more information on how to install Leaf.

leaf create <app-name> --v3 --basic --no-tests

Adding Leaf UI to your project

Leaf UI is available as an installable Leaf module. This means you can add Leaf UI through the Leaf CLI:

leaf install ui

Or through Composer:

composer require leafs/ui

From there, Leaf UI will be automatically available in your application. You can then start building your awesome UIs.

Loading Leaf UI on a route

Leaf UI pages can be created, but only show up in the DOM when they are called through the Leaf\UI::render method. This means that you will need to return the UI you want to call in the associated route. Let's say you have a component named HomePage. You can return this from the /home route like this:






 


 




<?php

use Leaf\UI;

require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/pages/Home/HomePage.php';

app()->get('/home', function () {
  UI::render(new HomePage());
});

app()->run();

If you're using Leaf MVC, Leaf API or Skeleton, you will call the views in your controller just as you would do with templating engines.

Usage With Leaf PHP has loaded