Download the PHP package sleekphp/sleekphp without Composer
On this page you can find all versions of the php package sleekphp/sleekphp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package sleekphp
sleekPHP Framework Documentation
sleekPHP is a lightweight, beginner-friendly PHP framework inspired by Laravel, designed to simplify web development with an MVC structure, basic ORM, and migration capabilities.
Table of Contents
- Installation
- Folder Structure
- Core Components
- Creating Routes
- Creating Controllers
- Using Views
- Command Line Interface (CLI)
- Using Models and ORM
- Database Migrations
- Running the Development Server
- Environment Configuration
- License
Installation
-
Clone or download the sleekPHP repository.
-
Navigate to the project root directory and install dependencies using Composer:
-
Run the following command to set up autoloading for the framework:
- Start a local development server (details provided in Running the Development Server).
Folder Structure
Here’s the basic structure of the sleekPHP framework:
Core Components
1. Router
The router handles HTTP requests and directs them to the appropriate controllers. Define routes in the routes/web.php
and routes/api.php
files.
2. Controller
Controllers are located in app/Controllers
. Each controller is responsible for handling requests and returning a response, usually by rendering a view.
3. View Engine
The view engine is designed to parse custom directives (@if
, @foreach
, @include
) in .php
files. Views are stored in app/Views
.
4. ORM and Model
The base Model
class in system/Core/Model.php
provides a simple ORM, enabling basic CRUD operations, along with querying methods.
5. Database Migrations
The Schema
and Blueprint
classes in system/Database
provide migration capabilities, allowing you to create and drop tables.
Creating Routes
Define routes in the routes/web.php
file. Routes can be mapped to controller methods:
- GET and POST routes are supported using
get()
andpost()
methods. - Use
dispatch()
inpublic/index.php
to handle routing based on the URL and request method.
Creating Controllers
Controllers are PHP classes located in app/Controllers
. Each method in the controller can be mapped to a route.
In this example, HomeController
has an index
method that loads the home.php
view with data.
Using Views
View files are stored in app/Views
and use the .php
extension. The view engine supports:
- Variables with
{{ $variable }}
syntax. - Conditional Statements with
@if
,@elseif
,@else
, and@endif
. - Loops with
@foreach
and@endforeach
. - Includes with
@include('viewName')
.
Example view file:
Command Line Interface (CLI)
The sleek
command file provides several commands for easy project management.
-
Make Controller:
This command creates a new controller in
app/Controllers
. -
Make Model:
This command creates a new model in
app/Models
with an ORM structure. -
Make View:
This command creates a new view file in
app/Views
. -
Make Migration:
Creates a new migration file in
database/migrations
. -
Run Migrations:
Runs all migrations, executing each
up
method to apply database changes. -
Run Development Server:
Starts a development server at
http://localhost:8000
.
Using Models and ORM
The base Model
class provides basic CRUD operations and querying capabilities.
Example usage:
-
Creating a Record:
-
Finding a Record by ID:
-
Using Where Clauses:
- First Record with Where:
Database Migrations
Define migrations to create or modify tables in database/migrations
.
Example migration to create a users
table:
To apply migrations, run:
Running the Development Server
To start the server, run:
The server will start at http://localhost:8000
.
Environment Configuration
Environment variables are managed through the .env
file. Common variables include:
Use getenv('VARIABLE_NAME')
in your code to access these variables.
License
sleekPHP is open-source software, and you're free to modify and distribute it.
This documentation provides a foundational guide for sleekPHP. Let me know if you have further questions or would like more details!