Link Search Menu Expand Document

Framework

Table of contents

  1. Helper Methods
    1. Get Server Date Time
    2. Generate Random Token
    3. App Constant
    4. Redirect
    5. Say (Internationalization)
    6. Base URL
    7. Root Path
    8. Get Environment
    9. Get Start
  2. Controller Lifecycle Overrides

When writing controller logic, you may often need to generate random strings, retrieve the current server time, or access configuration constants. This section lists the available helper methods provided by the Puko Framework to address these needs. These methods are directly accessible within your View, Service, or Console controllers.

Helper Methods

Get Server Date Time

Retrieves the current server date and time in the format Y-m-d H:i:s.

$dateTime = $this->GetServerDateTime();

Generate Random Token

Generates a random alphanumeric string (A-Z, a-z, 0-9). By default, it produces a 6-character string.

// Generates a 6-character token, e.g., "p4vRXo"
$token = $this->GetRandomToken();

// Generates a custom-length token
$longToken = $this->GetRandomToken(16);

App Constant

Retrieves a constant defined in the const section of your config/app.php file.

$apiEndpoint = $this->GetAppConstant('API_ENDPOINT');

Redirect

Redirects the user to a specified routing path.

// Redirects to the 'login' route
$this->RedirectTo('login', false);
  • First Parameter: The destination route string.
  • Second Parameter: A boolean. If true, the browser’s history is replaced (similar to location.replace). If false, the redirection is treated as a standard link click.

Say (Internationalization)

Fetches a localized string from the JSON schema files located in assets/master.

$welcomeMessage = $this->say('WELCOME_GUEST');

Base URL

Retrieves the base URL of your application (e.g., http://localhost:3000/).

$baseUrl = Framework::$factory->getBase();

Root Path

Retrieves the absolute server file system path to your project’s root directory (e.g., /var/www/html/puko).

$rootPath = Framework::$factory->getRoot();

Get Environment

Retrieves the current application environment setting (e.g., DEVELOPMENT, STAGING, or PROD).

$env = Framework::$factory->getEnvironment();

Get Start

Retrieves the precise PHP execution start time (microtime).

$startTime = Framework::$factory->getStart();

Controller Lifecycle Overrides

You can hook into the controller lifecycle by overriding the following methods:

public function BeforeInitialize()
{
    // Executed before the primary controller function
}

public function AfterInitialize()
{
    // Executed after the primary controller function
}