DALT.PHP
Framework Deep Dive1. Entry Point

Global Helper Functions

The essential toolbox that makes DALT feel like a modern framework

DALT includes a set of global functions that are available everywhere in your application. These are the "convenience glue" that keeps your controllers and views clean.

These functions are defined in framework/Core/functions.php and are loaded during the bootstrap process.


1. Debugging with dd()

The dd() (Dump and Die) function is your best friend when something isn't working:

dd($user, $posts, $_SESSION);

What it does:

  • Formats the output with a dark, readable CSS theme.
  • Uses var_export() to show the exact structure of your data.
  • Exits the script immediately (exit(1)), preventing any further code from running.

2. Rendering Views with view()

This is the primary way to send HTML to the browser.

return view('posts/index.view.php', [
    'posts' => $posts
]);

Key Features:

  • Variable Extraction: Uses extract($attributes) so the array keys become local variables in your view.
  • Priority Loading: It checks your app's resources/views/ first. If a file isn't found, it falls back to the .dalt platform. This allows you to "shadow" or override platform pages easily.

3. Flow Control: redirect() and abort()

redirect($path)

Simple wrapper for the header("Location: ...") call. It ensures the script stops executing immediately after sending the header.

abort($code)

Throws a Core\HttpException. This is caught by the entry point to show the appropriate error page (404, 403, 500).


4. Forms: old() and csrf_field()

old($key, $default)

Retrieves data that was "flashed" to the session during a failed validation. This ensures that when a user makes a mistake in a form, they don't lose everything they already typed.

csrf_field()

Generates a hidden HTML input containing a secure, random CSRF token:

<input type="hidden" name="_token" value="abc123...">

The Csrf middleware checks this token on every POST request to protect your users.


5. Path Management: base_path()

Never use relative paths like ../../config.php. They break if you move your files.

require base_path('config/database.php');

base_path() prepends the absolute path of your project root, ensuring that your includes always work regardless of where the script is executed from.


6. Logging: app_log()

When things go wrong, you still need to know what happened.

app_log("Payment failed for user " . $user->id);

This writes a timestamped message to storage/logs/app.log.


Key Takeaways

  1. Clean Syntax: Helpers allow you to write $user = old('email') instead of deep array lookups.
  2. Encapsulation: Complex logic (like checking if the Vite dev server is running) is hidden behind simple function calls.
  3. Always Available: Because they are loaded in bootstrap.php, you never need to require them manually in your controllers.

What's Good Here

✅ Provides the "developer experience" (DX) that people love in frameworks like Laravel
✅ Extremely lightweight implementation
✅ Centralizes path and view logic in one place
✅ Intentionally global for convenience in a learning framework

Design Note

Global functions are a trade-off between convenience and namespace pollution. For a learning framework where simplicity matters, this is the right choice. Production frameworks like Laravel use the same approach.


Now that you've seen the helpers, let's see how they are all wired together in the Bootstrap Process.

On this page