File structure
On this page, we’re going to look at the file structure of the CMS. As the CMS is a flat-file CMS, all content is saved in files, be it Markdown, HTML, or something else.
This is what we’ll cover:
Where are files saved?
Files are saved in the folder you specify in the config file (aloiacms.php) under the collections_path
key: config('aloiacms.collections_path')
.
The default location where the files are saved is: storage_path('app/collections')
.
You can change this to any folder you prefer, for example: storage_path('app/content')
.
Each model is saved in its own folder.
If we assume that you’re saving the Article model, which at its most basic form looks like this:
namespace AloiaCms\Models;
class Article extends Model
{
protected $folder = 'articles';
}
This model instance will be saved to storage/app/collections/articles/file-name.extension
.
How are models saved to files?
When you’re saving your first model, these are the steps the base model goes through to persist your data to disk:
- A “PreModelSaved” event is dispatched
- Properties and body content are converted to markdown/html and front matter is added
- We verify if you’ve supplied a filename (ex. Article::find(‘filename-here’))
- We verify if you’ve supplied the required front matter (none by default)
- We get the filepath for the model. This creates the folder if it doesn’t already exist (ex. articles)
- The content + front matter is persisted to a file on the filepath (step 5)
- A “PostModelSaved” event is dispatched
When you update a model, it goes through these exact steps and skips steps where possible.
Deleting models
As Aloia is a flat-file CMS, deleting a model is nothing more than deleting a file. Before deleting the file, a “PreModelDeleted” event is dispatched. After deleting the file, a “PostModelDeleted” event is dispatched.
You can hook into these events to do any cleanup you might need to do.