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
// 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']);
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']]
);
}
}