PHP code example of amirdev-byte / phlask

1. Go to this page and download the library: Download amirdev-byte/phlask 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/ */

    

amirdev-byte / phlask example snippets



PHLask\App;
use PHLask\Http\Request;
use PHLask\Http\Response;

// ایجاد نمونه از برنامه
$app = App::getInstance();

// تعریف مسیر GET ساده
$app->get('/', function(Request $request, Response $response) {
    return $response->json([
        'message' => 'سلام دنیا!',
        'version' => '1.0.0'
    ]);
});

// تعریف مسیر GET با پارامتر
$app->get('/users/{id}', function(Request $request, Response $response) {
    $userId = $request->param('id');
    
    // در اینجا می‌توانید اطلاعات کاربر را از دیتابیس دریافت کنید
    
    return $response->json([
        'id' => $userId,
        'name' => 'کاربر شماره ' . $userId,
        'email' => 'user' . $userId . '@example.com'
    ]);
});

// اجرای برنامه
$app->run();