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
Adding Routes
Routes map URLs to controller actions. Define your routes in the route file.
<?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
ControllerName/actionMethod, the second is the URL path.
Creating Controller Actions
Controllers handle HTTP requests and prepare data for views. Each route maps to a controller action.
<?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();
}
}
Creating Views
Views are PHP templates that render HTML. They receive data from controllers and can include styles, scripts, and elements.
<?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');?>
insertStyle()
Include CSS from render/style/[name].style.php
insertElement()
Include reusable components from render/element/[name].element.php
insertScript()
Include JavaScript from render/script/[name].script.php
Using Layouts
Layouts define the overall HTML structure and wrap your views. The default layout includes the head element and renders the body view.
<!DOCTYPE html>
<html>
<head>
<?=$this->insertElement('head');?>
</head>
<body>
<?=$this->insertView($bodyView);?>
</body>
</html>
Creating Reusable Elements
Elements are reusable partial templates like headers, footers, and navigation. They can access controller variables.
<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>
Adding a New Page: Complete Workflow
Follow these steps to add a new page to your application.
Add the Route
Register the URL path in your route file.
$route->register('EntryBang/products', '/products');
Create the Controller Action
Add a method to handle the request.
public function products()
{
$this->currentPage = 'products';
$this->bodyView = 'products';
$this->render();
}
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');?>
Test Your Page
Navigate to your new page in the browser.
http://localhost:8000/products