Skip to content
This repository was archived by the owner on Oct 4, 2024. It is now read-only.

leafsphp/skeleton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation



Leaf Skeleton





Leaf Skeleton

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.

Installation

It's recommended that you use Composer to install Leaf.

composer create-project leafs/skeleton <project-name>

This will start a new skeleton project.

Basic Info

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:5500

Building with skeleton

Most 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.

global methods

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.

app

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");

d

This method returns the leaf date object. You can use any Leaf Date method on d.

$timestamp = d()->random_timestamp();

dbRow

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");

fs

This returns the Leaf FS object. So you can use all it's methods on fs

fs()->create_folder("new_logs");

email

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

import a page, usually used to render HTML/PHP pages

import("App/errors/$code.php");

markup

Render markup as a response

markup("<h2>Hello</h2>");

plural

This method allows you to get the plural version of a string.

$word = "todo";
plural($word); // returns "todos"

render

This outputs a blade view.

function user() {
  render("user", ["username" => "Mychi"]);
}

requestBody

requestBody returns the whole body of a request.

$loginData = requestBody();
$username = $loginData["username"];

requestData

This method returns a particular parameter in the request body

$username = requestData("username");

respond

Outputs a JSON encoded response.

$data = ["name" => "BMW", "data" => ["id" => "1", "driver" => "Mychi"]];
respond($data);

respondWithCode

respondWithCode sends JSON encoded data with a code and the appropriate headers as a response

respondWithCode($data, 201);

Route

This method creates a new route. It takes in 3 parameters:

  • The route method(s)
  • The route
  • The handler
Route("GET|POST", "/me", function() {...});

sessionBody

This method returns all session data

$session_data = sessionBody();

sessionGet

Return a session variable

$user = sessionGet("user");

sessionSet

Add a new session variable

$user = sessionSet("user", ["id" => "1"]);

singular

This method allows you to get the singular version of a string.

$word = "todos";
singular($word); // returns "todo"

throwErr

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

view returns a blade view.

$output = view("user", ["username" => "Mychi"]);

Other Leaf Projects

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.

License

The LeafAPI framework is open-source software licensed under the MIT license.

View Leaf's docs here

About

A boiler-plate application for rapid development.

Topics

Resources

Code of conduct

Contributing

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

 
 
 

Contributors