PHP code example of shaik-obydullah / lime-php-framework

1. Go to this page and download the library: Download shaik-obydullah/lime-php-framework library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shaik-obydullah / lime-php-framework example snippets


use Lime\Router;

Router::get('/', 'HomeController@index');
Router::post('/login', 'AuthController@login');
Router::match(['GET', 'POST'], '/register', 'AuthController@register');
Router::get('/user/{id}', 'UserController@show');

// Route: /user/{id}
Router::get('/user/{id}', 'UserController@show');

// Controller
class UserController extends Controller
{
    public function show(string $id): void
    {
        // $id is extracted from the URL
    }
}



declare(strict_types=1);

namespace App\Controller;

use Lime\Controller;

class HomeController extends Controller
{
    public function index(): void
    {
        $this->view('home/index', [
            'title' => 'Welcome',
        ]);
    }
}

// In controller: $this->view('home/index', ['title' => 'Hello']);

<!-- App/View/home/index.php -->
<h1><?= htmlspecialchars($title) 

use Lime\Database;

// Fetch a single row
$user = Database::fetch('SELECT * FROM users WHERE id = ?', [1]);

// Fetch all rows
$users = Database::fetchAll('SELECT * FROM users');

// Insert and get the last insert ID
$id = Database::insert(
    'INSERT INTO users (name, email) VALUES (?, ?)',
    ['John', '[email protected]']
);

// Execute a statement (UPDATE, DELETE)
$affected = Database::execute(
    'UPDATE users SET status = ? WHERE id = ?',
    ['online', 1]
);



declare(strict_types=1);

namespace App\Model;

use Lime\Model;

class User extends Model
{
    public static function findByEmail(string $email): ?array
    {
        return self::fetchOne('SELECT * FROM users WHERE email = ?', [$email]);
    }

    public static function create(array $data): int
    {
        return self::execute(
            'INSERT INTO users (name, email, password) VALUES (?, ?, ?)',
            [$data['name'], $data['email'], $data['password']]
        );
    }
}

my-app/
├── App/
│   ├── Controller/
│   ├── Database/
│   │   └── Migrations/
│   ├── Router/
│   │   └── web.php
│   └── View/
├── Public/
│   ├── index.php
│   └── .htaccess
├── System/
│   ├── Bootstrap.php
│   ├── Controller.php
│   ├── Database.php
│   ├── Migration.php
│   ├── Model.php
│   ├── Router.php
│   └── View.php
├── storage/
├── .env
├── .htaccess
├── composer.json
└── lime
bash
php lime migrate
nginx
server {
    listen 80;
    server_name example.com;
    root /path/to/project/Public;

    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
         }
}