PHP code example of bayrameker / my-bolt-framework

1. Go to this page and download the library: Download bayrameker/my-bolt-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/ */

    

bayrameker / my-bolt-framework example snippets


$router->get('/home', [App\Controllers\HomeController::class, 'index']);



namespace App\Controllers;

use Core\Controller;
use Core\Request;
use Core\Response;
use Core\ViewRenderer;
use App\Services\HomeService;

class HomeController extends Controller
{
    protected $homeService;

    public function __construct(HomeService $homeService)
    {
        $this->homeService = $homeService;
    }

    public function index(Request $request, Response $response)
    {
        $homeData = $this->homeService->getHomeData();
        $viewRenderer = new ViewRenderer('home/index', [
            'title' => $homeData->title,
            'message' => $homeData->message,
            'layout' => 'layout'
        ]);
        $viewRenderer->render();
    }
}



namespace App\Services;

use App\Repositories\HomeRepository;

class HomeService
{
    protected $homeRepository;

    public function __construct(HomeRepository $homeRepository)
    {
        $this->homeRepository = $homeRepository;
    }

    public function getHomeData()
    {
        return $this->homeRepository->getHomeData();
    }
}



namespace App\Repositories;

use App\Models\Home;

class HomeRepository
{
    public function getHomeData()
    {
        return new Home('Home Page', 'Welcome to My Bolt Framework!');
    }
}



namespace App\Models;

class Home
{
    public $title;
    public $message;

    public function __construct($title, $message)
    {
        $this->title = $title;
        $this->message = $message;
    }
}

<main>
    <h1><?= $title ?? 'Default Title' 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= $title ?? 'Default Title' 
sh
php bolt serve