Skip to main content

Source Type Control

In Phlame, the Source class serves as a tool for managing variables and controlling the content displayed on web pages linked to your router. It offers functionality to streamline code organization and enhance the user experience by allowing the developer to adjust the content based on necessary factors.

Utilizing Source for Changing Content-Type

Source can be use for changing the content type of the output, this allows you to change the content type of the sent output, in a way that is compatible with what your application requires.

Syntax:

Source::type(<content type necessary>);

Example:

Source::type('application/json');

You can use any type that are allowed, as its a simply just changing headers.

note

Use the type method at the beginning of your callbacks to change the content type.

Example of a Phlame Source Type Control

index.php
<?php
session_start();
require_once '.config/_init.php';

$router = new Router();

// Add a static route
$router->addRoute('/<name>', function($name) {
Source::type('application/json');
echo json_encode(["name" => $name]);
});

// More routes can be created

$router->route();
?>