Project structure
Before writing code it helps to know where things live. In a Laminas project every folder has one job, and new files almost always go into the module folder.
Folders in the project root
| Folder or file | What it holds |
|---|---|
config | Application configuration and the module list |
config/autoload | Shared configuration: global.php and local.php |
module | Your code, organised into modules |
public | The site root: index.php, styles, scripts, images |
data | Cache and other files the application creates |
vendor | Packages downloaded by Composer; never edited by hand |
composer.json | The package list and class loading rules |
The entry point
Every request to the site goes to public/index.php. It includes Composer's class loader, reads the configuration and runs the application:
// public/index.php (the main lines)
use Laminas\Mvc\Application;
chdir(dirname(__DIR__));
include __DIR__ . '/../vendor/autoload.php';
$appConfig = require __DIR__ . '/../config/application.config.php';
Application::init($appConfig)->run();The chdir() line makes the project root the current folder, so paths in the configuration are written from the root: data/cache, config/autoload. You normally never change this file.
The config folder
| File | Purpose |
|---|---|
application.config.php | Startup settings: where modules and configuration come from, whether caching is on |
modules.config.php | The list of enabled modules |
autoload/global.php | Settings shared by all machines |
autoload/local.php | Passwords and keys of one particular machine |
The Application module
A module is a folder with the code of one part of the site. The skeleton ships with one module:
module/Application/
├── config/
│ └── module.config.php
├── src/
│ ├── Controller/
│ │ └── IndexController.php
│ └── Module.php
└── view/
├── application/index/index.phtml
├── error/404.phtml
├── error/index.phtml
└── layout/layout.phtmlconfig holds the module's configuration, src holds PHP classes and view holds page templates, called view scripts (files with the .phtml extension). layout/layout.phtml is the common frame of all pages, and error/404.phtml is the "not found" page.
The public folder
Only this folder is visible from the browser. The file public/css/style.css opens at /css/style.css. Everything else — code, configuration, passwords — sits one level above and cannot be reached by a link.
Common mistake
Do not put your own classes and view scripts into vendor and do not edit files inside it: the next composer install or composer update wipes the changes. Your code lives in module, settings live in config, and vendor belongs entirely to Composer.