How banago/simple-php-website works
Project type and purpose
• This is a minimal, beginner-friendly PHP website. It follows a simple “flat-file MVC” style:
• No database—content is stored in .phtml files.
• A front controller (index.php) routes requests.
• Separation of concerns between content, logic, and template.
File structure
• Top-level files:
• .htaccess – defines URL rewrites for “pretty” URIs.
• index.php – single entry point (front controller).
• readme.md – project description and instructions.
• Directories:
• content/ – page templates (home, about-us, contact, products, 404).
• includes/ – PHP logic (configuration and helper functions).
• template/ – presentation layer (main layout template.php + style.css).
• No database, no external services. All routing and rendering happen on the PHP server.
Key insights from the README
• The site uses query strings (?page=about) and supports pretty URIs if enabled in config.php.
• Demonstrates separation of concerns: logic in /includes, content in /content, layout in /template.
Main components
a. Client-side browser
b. Web server (Apache or PHP’s built-in server)
c. Front Controller (index.php)
d. Configuration & Helper Module (includes/config.php, includes/functions.php)
e. Content Module (content/*.phtml)
f. Template/Layout Module (template/template.php, template/style.css)
g. URL Rewriter (.htaccess, optional)
Relationships & data flow
1. Browser sends HTTP request → Web server
2. Web server hands request to index.php (front controller)
3. index.php reads config.php to check pretty_uri flag and loads functions.php
4. Based on URL or ?page= parameter, it selects the appropriate .phtml in /content
5. The selected content is injected into /template/template.php, which links style.css
6. Template outputs the final HTML → Browser receives response
7. If page not found, a 404 content file is served
Architectural patterns and principles
• Front Controller pattern (all requests go through index.php)
• Separation of Concerns:
• Configuration & utilities (includes/)
• Content (content/)
• Presentation (template/)
• Simple routing mechanism with optional URL rewriting
Essential elements
• Clear labels: “Browser”, “Apache/PHP Server”, “index.php (Front Controller)”, etc.
• Logic layer (includes) – blue
• Content layer – green
• Presentation layer – orange