Skip to content

Commit

Permalink
Merge pull request #18 from DasunNethsara-04/main
Browse files Browse the repository at this point in the history
README updated
  • Loading branch information
DasunNethsara-04 authored Nov 2, 2024
2 parents a0224de + dc7412b commit 1d7e318
Showing 1 changed file with 70 additions and 16 deletions.
86 changes: 70 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<p align="center">
<img src="https://github.com/user-attachments/assets/ab329545-9c44-4e85-aabe-6f4dc0f0512c" alt="icon-192" width="192" height="192">
</p>
<h1 align="center">ZenithPHP</h1>
<h1 align="center">ZenithPHP</h1>

Welcome to **ZenithPHP**, a simple and lightweight PHP framework designed to streamline web application development.
ZenithPHP follows the MVC (Model-View-Controller) architecture and provides developers with a clean and flexible
foundation to build modern PHP applications with ease.
Welcome to **ZenithPHP**, a simple and lightweight PHP framework designed to streamline web application development. ZenithPHP follows the MVC (Model-View-Controller) architecture and provides developers with a clean and flexible foundation to build modern PHP applications with ease.

## Official Documentation
You can find the official documentation for ZenithPHP at [ZenithPHP Documentation](https://zenithphp-framework.github.io/start.html). The documentation provides detailed information on how to get started with ZenithPHP, including installation instructions, routing, controllers, models, views, and more.

## Features

Expand All @@ -14,14 +15,15 @@ foundation to build modern PHP applications with ease.
- **Simple Namespacing**: Eliminate the need for `require_once` with proper namespacing.
- **Security Built-in**: Features like password hashing and input validation to keep your app secure.
- **Easy to Extend**: Customize the framework to suit your application’s needs with minimal effort.
- **Pluto Template Engine**: Simplifies view rendering with a clean syntax and powerful directives.

## Installation

To get started with ZenithPHP, follow the instructions below:

1. Clone the repository:
```bash
https://github.com/ZenithPHP-Framework/full-zenith-framework.git
git clone https://github.com/ZenithPHP-Framework/full-zenith-framework.git
```

2. Navigate to the project directory:
Expand Down Expand Up @@ -55,7 +57,7 @@ To get started with ZenithPHP, follow the instructions below:
- **.env**: Environment variables for the application.
- **.env.example**: Example environment variables file.
- **composer.json**: Composer dependencies file.
- **cli**: Command-line interface for running the application and create models and controllers.
- **cli**: Command-line interface for running the application and creating models and controllers.
## How to Get Started
Expand All @@ -71,13 +73,13 @@ To create your first route:
```php
use ZenithPHP\Core\Controller\Controller;
class WelcomeController extends Controller
{
public function index()
{
$this->view('welcome');
}
}
class WelcomeController extends Controller
{
public function index()
{
$this->view('welcome');
}
}
```
3. Now, create a new view file inside `View/welcome.php`:
Expand All @@ -87,8 +89,8 @@ To create your first route:
4. Visit `http://localhost:8000/welcome` to see the result.
## Working with APIs
Now you can create APIs with ZenithPHP. Here's how you can create a simple API:

1. First, create a new route in `App/routes.php`:
Expand All @@ -110,7 +112,7 @@ Now you can create APIs with ZenithPHP. Here's how you can create a simple API:
{
protected string $table_name = 'users';
}
```

4. Create a new controller. For that, you can use the CLI tool:
```bash
Expand All @@ -124,7 +126,7 @@ Now you can create APIs with ZenithPHP. Here's how you can create a simple API:
use ZenithPHP\Core\Http\Request;
use ZenithPHP\App\Models\User;
class WelcomeController extends Controller
class UserController extends Controller
{
public function index(Request $request, Response $response)
{
Expand All @@ -137,6 +139,58 @@ Now you can create APIs with ZenithPHP. Here's how you can create a simple API:

6. Visit `http://localhost:8000/api/users` to see the JSON response.


## Pluto Template Engine

The **Pluto** template engine in ZenithPHP allows you to easily build dynamic views with clean and readable syntax. Here’s a quick overview of its directives:

### Pluto Syntax

- **Variable Output**: Use `<< $variable >>` to output PHP variables in the view.
- **Conditional Statements**: Pluto offers `@if`, `@elseif`, `@else`, and `@endif` directives for conditional rendering.
- **Looping**: Use `@foreach` and `@endforeach` to iterate over collections.
- **Comments**: Use `<< // >>` to add comments in your templates.
- **Yielding Sections**: Use `@yield` to define a section that will be replaced with content from child templates.
- **Section Definition**: Use `@section` to define a section that can be filled in child templates.
### Example Syntax
`HomeController.php`
```php
class HomeController extends Controller
{
public function index(Request $request, Response $response)
{
return view('home', [
'username' => 'John Doe',
'userRole' => 'admin',
'items' => [
(object) ['name' => 'Laptop', 'price' => '$999'],
(object) ['name' => 'Smartphone', 'price' => '$499'],
]
]);
}
}
```
`home.pluto.php`
```php
<!-- Displaying a variable -->
<< $username >>
<!-- Conditional Statement -->
@if ($userRole == 'admin')
<p>Welcome, Admin!</p>
@elseif ($userRole == 'member')
<p>Welcome, Member!</p>
@else
<p>Welcome, Guest!</p>
@endif
<!-- Looping Through Data -->
@foreach ($items as $item)
<p><< $item->name >> - << $item->price >></p>
@endforeach
```
## Security Features
- **Password Hashing**: Built-in password hashing methods for user authentication.
Expand Down

0 comments on commit 1d7e318

Please sign in to comment.