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/ */
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;
}
}