Get Started
Follow these steps to create your first FastPress application.
1. Define a Route
Add the following code to your app/routes.php file:
<?php
$app->get('/test', 'TestController@index');
2. Create a Controller
In app/controller/DefaultController.php:
<?php
namespace App\Controller;
use Fastpress\Presentation\View;
use App\Service\DefaultService;
class DefaultController {
private $defaultService;
public function __construct(DefaultService $defaultService) {
$this->defaultService = $defaultService;
}
public function index(View $view) {
$message = $this->defaultService->sayHello();
$view->render('index.html', ['message' => $message]);
}
}
3. Create a Service
In app/service/DefaultService.php:
<?php
namespace App\Service;
use App\Repository\DefaultRepository;
class DefaultService {
private $defaultRepository;
public function __construct(DefaultRepository $defaultRepository) {
$this->defaultRepository = $defaultRepository;
}
public function sayHello() {
$name = $this->defaultRepository->getName();
return "Hello, $name!";
}
}
4. Create a Repository
In app/repository/DefaultRepository.php:
<?php
namespace App\Repository;
class DefaultRepository {
public function getName() {
// This would normally be a database call
return "World";
}
}
5. Create a View
In app/view/index.html:
<?php $this->extend('layout') ?>
<?php $this->block('content') ?>
<h1>User Profile</h1>
<?php if (isset($message)): ?>
<p>Welcome, <?= $this->e($message) ?></p>
<?php else: ?>
<p>No name provided</p>
<?php endif; ?>
<?php $this->endBlock() ?>
Ensure your layout file app/view/layout.html includes <?php $this->content('content') ?> to render the content of this view.
Configuration
All settings can be found in conf.dev.php.