---
title: "Jimbo Plugin"
url: https://festi.dev/8.0/Plugins/Jimbo/
---

# Jimbo Plugin

Jimbo Plugin is a system plugin that provides all essential functionalities for creating an admin panel within the Festi Framework. It includes authentication, settings management, routing, making it easy to build and manage administrative interfaces.

## For install and update plugins use url:

> /festi/install/

## Settings

### `SETTING_KEY_NON_AUTH_EXCEPTION`

The `SETTING_KEY_NON_AUTH_EXCEPTION` setting controls whether the plugin should throw an exception for unauthorized access attempts on non-auth URLs, rather than redirecting users to the login form.

```php
$plugin->addSetting(JimboPlugin::SETTING_KEY_NON_AUTH_EXCEPTION, true);
```

## Requirements

`festi-team/festi-framework-core` with `Festi\Core\Plugin\IUrlRuleFinder` and `UrlRuleMatcher`: `develop` from
commit `6e5dd56e` (PHP_FestiFramework !736) on. `JimboPlugin` implements that interface and routes a request with
that matcher, so on an older core it stops with "Interface not found" on the first request. A project that has
Jimbo as a git submodule must update its core together with the submodule.

PHP 8.1 or newer. The members of the core that Jimbo overrides have native types from commit `6546dbeb` on, and Jimbo
declares the same types: `onInit()`, `onDisplayMain()`, `install()` and `getResponseModel()` in the plugin,
`getUrlRules()`, `getSettings()` and `addUrlRule()` in `JimboObject`. A class of a project that overrides one of them
has to declare the same types.

### The `index.php` of a dashboard install

`bindRequest()` throws `NotFoundException` for a url no rule matches and `PermissionsException` for a page the user
may not open; the status and the body are up to `index.php`. `install/dashboard/index.php` now answers with 404, 403
and, for anything else, 500 with a fixed text; the error itself goes to the PHP error log. The installer copies that file into the project once, so a project that was installed
earlier still has the old ending, `catch (Exception $exp) { echo $exp->getMessage(); }`, which answers an unknown url
with an empty page and HTTP 200. Replace it with the catch blocks of the current template.

### The `.htaccess` of an install

`install/dashboard/.htaccess` and `install/site/.htaccess` refuse a request for a `.php` file in `plugins/` with 403:
`RewriteRule ^plugins/.*\.php(/|$) - [F,NC]`. A plugin is loaded by `index.php`; its files are not pages. Static files
of a plugin are served as before. A project that was installed earlier has to add the rule to its own `.htaccess`,
before the rule that lets `.php` files through.

## URL Rules

### Non-Auth URL Rule

The Non-Auth URL Rule allows specific URLs to be accessed without requiring user authentication. This is useful for public routes such as login, signup, password recovery, or API endpoints.

#### Adding Non-Auth URLs

You can directly add non-auth URLs by defining them within your plugin code.

```php
$plugin = Core::getInstance()->getSystemPlugin('Jimbo');
$plugin->addNonAuthUrl('/custom/public/url/');
```

#### Adding Non-Auth URLs Using Events

To add non-auth URLs through an event, use the ConfigureRequestUrlRulesEvent. This method is ideal for setting non-auth routes during plugin initialization.

```php
$this->addEventListener(
    ConfigureRequestUrlRulesEvent::EVENT_TYPE,
    function (ConfigureRequestUrlRulesEvent $event) {
        $event->addNonAuthUrl('/public/url/');
    }
);
```

#### Supporting Regular Expressions

You can also define non-auth URLs using regular expressions for more dynamic routing.

` '#^/api/public/.*#'`

## Menu

Menu items are stored in the `festi_menus` table. Visibility is controlled by `festi_menu_permissions` (role-based) or by `festi_sections` (permission section-based).

### Areas

Areas are custom strings stored in `festi_url_areas`. A project can define any areas it needs, but the two conventional ones are:

| Area | Usage |
|------|-------|
| `backend` | Admin panel |
| `default` | Frontend website |

### Retrieving menu items in a template

`getStructureMenu(string $area)` returns `IMenuItem[]` — ready-to-render objects, not plain arrays.

```php
$items = $this->core->getSystemPlugin()->getStructureMenu('default');
```

Pass the result directly to `mainNavbar()->setMenuItems()`:

```php
$mainNav = $this->ui->mainNavbar()
    ->setLogoUrl('/static/images/logo.png')
    ->setMenuItems($items)
    ->fetch();
```

### Adding a menu item (CLI)

Use `festi-dgs-exec` with `--access-token` (the token from the `access_token` column on the `users` table):

```bash
./vendor/bin/festi-dgs-exec \
  --plugin Jimbo \
  --dgs festi_menus \
  --action insert \
  --values '{"caption":"My Item","url":"/my-url/","order_n":10,"area":"default"}' \
  --path src/site \
  --access-token <token>
```

List existing items:

```bash
./vendor/bin/festi-dgs-exec --plugin Jimbo --dgs festi_menus --action list \
  --path src/site --access-token <token>
```

Remove an item by id:

```bash
./vendor/bin/festi-dgs-exec --plugin Jimbo --dgs festi_menus --action remove \
  --values '{"id":42}' --path src/site --access-token <token>
```

### Anonymous (unauthenticated) users

Anonymous users have role `DefaultUser::TYPE_ANONYM = -1`. To make a menu item visible to guests, add a `festi_menu_permissions` row with `id_role = -1`:

```sql
INSERT INTO festi_menu_permissions (id_role, id_menu) VALUES (-1, :id_menu);
```

### Section-based visibility

If `id_section` is set on a menu item, it is only shown when the user's granted mask for that section is `> 0` (checked via `festi_sections_user_types_permission`). Items with `id_section IS NULL` rely solely on `festi_menu_permissions`.

## Events

### ConfigureRequestUrlRulesEvent

When you need to modify or add some rules for URL routing, you can use that event. Additionally, through that event, you
are able to add a URL that will be accessible without authorization.

To use this event add `init.php` into your plugin directory.

- `addNonAuthUrl` method to add URL to whitelist for non-authenticated actions, e.g. webhooks etc.
- `addUrlRule` method to add new URL rule from code.

```php
<?php

$this->addEventListener(
    ConfigureRequestUrlRulesEvent::EVENT_TYPE,
    function (ConfigureRequestUrlRulesEvent $event) {
        $event->addNonAuthUrl('/some/plugin/url/');
        
        $event->addUrlRule(' ~^/test/$~', 'Test', 'onDisplayTest');
    } 
);
```

### RequestExceptionEvent

`RequestExceptionEvent` is dispatched when a permission exception is triggered.

### ResponseErrorEvent

`ResponseErrorEvent` is dispatched when an exception occurs.

### SignInErrorEvent

`SignInErrorEvent` is triggered when a user fails to sign in due to incorrect credentials, account restrictions, or other authentication errors. It allows handling failed login attempts, logging errors, or displaying custom messages.

### SignInEvent

`SignInEvent` is triggered upon a successful user login. It allows executing additional actions like logging sign-ins, updating last login timestamps, or redirecting users to a specific page.

### SignInRedirectEvent

`SignInRedirectEvent` is fired after a successful login but before redirecting the user. It enables customization of the redirection process, such as directing different user roles to specific pages.

### SignOutEvent

`SignOutEvent` is triggered when a user logs out. It can be used to clear session data, log user activity, or perform other cleanup actions.
