Bhitti Documentation

Developer documentation for the lightweight, PHP-FPM-oriented Bhitti framework.

View the Project on GitHub sayedsahin/bhitti-doc


layout: default title: Upgrade from v0.2.0 ————————–

Upgrade from v0.2.0

Bhitti v0.3.0 introduces three developer-facing changes.

1. Native view rendering moved to the Response API

Previously:

public function index(): string
{
    return view('users.index', [
        'users' => $users,
    ]);
}

Use:

public function index(): Response
{
    return response()->view('users.index', [
        'users' => $users,
    ]);
}

Import the response class when using a return type:

use Bhitti\Http\Response;

For a non-200 response:

public function notFound(): Response
{
    return response()
        ->view('errors.404')
        ->status(404);
}

2. Optional Twig template support

v0.3.0 adds official Twig support.

Install Twig in applications that want to use it:

composer require twig/twig

Render a Twig template:

public function index(): Response
{
    return response()->twig('users.index', [
        'users' => $users,
    ]);
}

Without a .twig suffix, the default HTML template is resolved as:

resources/views/users/index.html.twig

Explicit Twig filenames can also be used:

return response()->twig('feeds/rss.xml.twig', $data);

For non-HTML output:

return response()
    ->twig('feeds/rss.xml.twig', $data)
    ->header('Content-Type', 'application/xml');

Native PHP templates remain available:

resources/views/*.view.php

3. Controller view return types

Controller methods that previously returned rendered view strings:

public function index(): string
{
    return view('users.index');
}

should now return Response:

public function index(): Response
{
    return response()->view('users.index');
}

The same applies to Twig:

public function index(): Response
{
    return response()->twig('users.index');
}

Upgrade checklist

Update:

return view('example');

to:

return response()->view('example');

Change the controller return type:

string

to:

Response

and add:

use Bhitti\Http\Response;

When using Twig:

composer require twig/twig

Then:

return response()->twig('example');

No other application changes are required for this release.