NanoMVC

Plugin: BlogMenu

The blogmenu plugin is a utility library designed to extract blog categories (controllers) and blog articles (controller methods) from your NanoMVC application. It uses structured metadata comments in both controllers and their methods.

How to Use

$this->load->library(​'blogmenu');
$categories = $this->blogmenu->​get_categories();
$articles = $this->blogmenu->​get_articles();

How to Define Metadata

Controller (Category)

At the top of your controller file, place the following metadata comment on the first line:

<?php // -> as categorie: { "name": "Category Name", "created": "2025-08-01 22:17" } ?>

Method (Article)

For each method (must be public and not start with an underscore), add metadata in the PHPDoc using the @blog tag:

/**
 * @blog {
 *   "name": "Customize Core",
 *   "description": "Learn how to safely override NanoMVC core without affecting updates.",
 *   "created": "2025-07-15 19:00"
 * }
 */

Available Methods

get_categories(​?string $controller = null, string $order = 'created desc')

Scans controller files and returns an array of categories (controllers) with parsed metadata.

get_articles(​?string $action = null, string $order = 'created desc', ?string $controller_name = null, ?string $act = null)

Scans the methods of the current or another controller and returns all articles with their metadata.

If $controller_name is provided, BlogMenu will try to load that controller from either the myapp or myfiles paths. If not found, an exception will be thrown. When loaded, the controller will be instantiated with the given controller and action names, allowing metadata extraction from another controller's articles.

Get next and previous article: get_nav(array &$items, string $current): array

Returns pre and next items relative to the current article key.

[
  'pre' => [ ... ],  // previous article or empty array
  'next' => [ ... ]  // next article or empty array
]

pagination(array &$items, int $limit = 1): int|bool

Splits the list of articles into pages and adds a _page index to each article.

Each article in $items gets a _page key with its page number. Example: if limit is 3 and you have 8 articles, they will be marked with pages 1, 1, 1, 2, 2, 2, 3, 3.

Validation

← to Customize Core to Useful Plugins →

← Back to Documentation