info Overview

The entry module is the main entry point for your BoomStick application. It follows the MVC (Model-View-Controller) pattern and provides a structured way to build web applications. This guide uses module/entry-docs as a reference implementation.

module/entry-bang/
├── controller/             # Request handlers
│   └── EntryBang.ctlr.php
├── lib/                    # Module-specific classes
│   └── EntryBang.class.php
├── public/                 # Web root (index.php, assets)
│   ├── index.php           # Application entry point
│   ├── css/
│   └── js/
├── render/                 # Templates and presentation
│   ├── element/            # Reusable components
│   ├── layout/             # Page layouts
│   ├── script/             # Inline JavaScript
│   ├── style/              # Inline CSS
│   └── view/               # Page templates
├── route/                  # URL routing
│   └── EntryBang.route.php
└── version.php

alt_route Adding Routes

Routes map URLs to controller actions. Define your routes in the route file.

description route/EntryBang.route.php
<?php
namespace BoomStick\Module\EntryBang\Route;
use BoomStick\Lib\Route;

class EntryBang extends Route
{
    public function __construct()
    {
        $this->module = str_replace('/route', '', __DIR__);
    }
}

$route = new EntryBang();

// Register your routes
$route->register('EntryBang/index', '/');              // Home page
$route->register('EntryBang/about', '/about');         // About page
$route->register('EntryBang/contact', '/contact');     // Contact page
$route->register('EntryBang/notFound', '/not-found');  // 404 page
info Route Format: The first parameter is ControllerName/actionMethod, the second is the URL path.

settings_remote Creating Controller Actions

Controllers handle HTTP requests and prepare data for views. Each route maps to a controller action.

description controller/EntryBang.ctlr.php
<?php
namespace BoomStick\Module\EntryBang\Controller;
use BoomStick\Lib\Controller;

class EntryBang extends Controller
{
    // Home page action
    public function index()
    {
        $this->pageTitle = 'Welcome';
        $this->bodyView = 'index';
        $this->render();
    }

    // About page action
    public function about()
    {
        $this->pageTitle = 'About Us';
        $this->bodyView = 'about';
        $this->render();
    }

    // Contact page action
    public function contact()
    {
        $this->pageTitle = 'Contact';
        $this->bodyView = 'contact';
        $this->render();
    }

    // 404 handler
    public function notFound()
    {
        $this->bodyView = 'not-found';
        header("HTTP/1.1 404 Not Found");
        $this->render();
    }
}
check_circle $this->variableName - Pass data to views
check_circle $this->bodyView - Specify which view to render

visibility Creating Views

Views are PHP templates that render HTML. They receive data from controllers and can include styles, scripts, and elements.

description render/view/about.view.php
<?php // Include inline styles for this view ?>
<?=$this->insertStyle('about');?>

<?php // Include reusable navigation element ?>
<?=$this->insertElement('nav');?>

<main class="container my-5">
    <h1><?=$pageTitle;?></h1>
    <p>This is the about page content.</p>
</main>

<?php // Include inline scripts for this view ?>
<?=$this->insertScript('about');?>
style insertStyle()

Include CSS from render/style/[name].style.php

extension insertElement()

Include reusable components from render/element/[name].element.php

code insertScript()

Include JavaScript from render/script/[name].script.php

view_quilt Using Layouts

Layouts define the overall HTML structure and wrap your views. The default layout includes the head element and renders the body view.

description render/layout/default.layout.php
<!DOCTYPE html>
<html>
<head>
    <?=$this->insertElement('head');?>
</head>
<body>
    <?=$this->insertView($bodyView);?>
</body>
</html>

extension Creating Reusable Elements

Elements are reusable partial templates like headers, footers, and navigation. They can access controller variables.

description render/element/nav.element.php
<nav class="navbar navbar-dark bg-dark">
    <div class="container">
        <a class="navbar-brand" href="/">My App</a>
        <ul class="navbar-nav flex-row">
            <li class="nav-item">
                <a class="nav-link <?=$currentPage === 'index' ? 'active' : '';?>" href="/">Home</a>
            </li>
            <li class="nav-item">
                <a class="nav-link <?=$currentPage === 'about' ? 'active' : '';?>" href="/about">About</a>
            </li>
        </ul>
    </div>
</nav>

play_circle Adding a New Page: Complete Workflow

Follow these steps to add a new page to your application.

1
Add the Route

Register the URL path in your route file.

$route->register('EntryBang/products', '/products');
2
Create the Controller Action

Add a method to handle the request.

public function products()
{
    $this->currentPage = 'products';
    $this->bodyView = 'products';
    $this->render();
}
3
Create the View

Create the view file at render/view/products.view.php.

<?=$this->insertStyle('index');?>
<?=$this->insertElement('nav');?>

<main class="container my-5">
    <h1>Products</h1>
    <p>Your products content here.</p>
</main>

<?=$this->insertScript('index');?>
4
Test Your Page

Navigate to your new page in the browser.

http://localhost:8000/products