Use this skeleton application to quickly setup and start working on a new Leaf PHP application without using a full-blown framework. Unlike Leaf MVC and Leaf API, Skeleton keeps leaf as is, and doesn't build on top of it, it's perfect for creating smaller projects.
It's recommended that you use Composer to install Leaf.
composer create-project leafs/skeleton <project-name>This will start a new skeleton project.
C:.This is the default directory structure that leaf skeleton offers, although you can customize it in any way you want. Simply edit the Config/paths.php file when you're done re-arranging Skeleton.
You can run your skeleton app with php's server:
php -S localhost:5500Most of your work will go on in the App/Routes.php file. You can define routes, use controllers and models...
An example has been provided on using both controllers and models. You can refer to this if you have any issues.
Skeleton is just Leaf, so please refer to Leaf's documentation for any functionality you may need.
These are simple-to-use functions that are available everywhere in your application. You can call these functions in your routes, controllers and everywhere you need them.
This method returns the base Leaf instance. You can perform whatever operation you need on the app method.
app()->response->respond(...);
app()->resource("/home", "HomeController");This method returns the leaf date object. You can use any Leaf Date method on d.
$timestamp = d()->random_timestamp();This method returns a row in a database table. It takes in 3 parameters:
- The table to use
- The row id
- The fields to return (optional, will return all if nothing is specified)
$user = dbRow("users", "1");
$item = dbRow("items", 2, "name, user_id");This returns the Leaf FS object. So you can use all it's methods on fs
fs()->create_folder("new_logs");This method allows you to write an email directly
email([
"subject" => "This is a full Write Test",
"template" => "./template.html",
"recepient_email" => "mychi.darko@gmail.com",
"sender_name" => "Leaf PHP Framework",
"attachment" => "./../attachment.txt"
]);import a page, usually used to render HTML/PHP pages
import("App/errors/$code.php");Render markup as a response
markup("<h2>Hello</h2>");This method allows you to get the plural version of a string.
$word = "todo";
plural($word); // returns "todos"This outputs a blade view.
function user() {
render("user", ["username" => "Mychi"]);
}requestBody returns the whole body of a request.
$loginData = requestBody();
$username = $loginData["username"];This method returns a particular parameter in the request body
$username = requestData("username");Outputs a JSON encoded response.
$data = ["name" => "BMW", "data" => ["id" => "1", "driver" => "Mychi"]];
respond($data);respondWithCode sends JSON encoded data with a code and the appropriate headers as a response
respondWithCode($data, 201);This method creates a new route. It takes in 3 parameters:
- The route method(s)
- The route
- The handler
Route("GET|POST", "/me", function() {...});This method returns all session data
$session_data = sessionBody();Return a session variable
$user = sessionGet("user");Add a new session variable
$user = sessionSet("user", ["id" => "1"]);This method allows you to get the singular version of a string.
$word = "todos";
singular($word); // returns "todo"Throws a json encoded error with appropraite headers.
throwErr("user not found", 404);Note that throwErr pauses code execution, and so, no code after throwErr runs. You can use this with conditional statements for a better effect.
if (!$user->isLoggedIn) throwErr("User not logged in");view returns a blade view.
$output = view("user", ["username" => "Mychi"]);Leaf API is a lightweight PHP MVC framework for rapid API development. It serves as minimal MVC wrapper around Leaf PHP Framework which allows you to use Leaf in an MVC environment. It also comes along with a bunch of handy tools which can speed up your development.
Read the docs.
The LeafAPI framework is open-source software licensed under the MIT license.
