October CMS resources and help articles

Simple and to the point. Optimized by the community.

Add a backend page to view your plugin settings

5
by mjauvin, last modified on August 5th, 2019

Plugin's settings registration:

    public function registerSettings()
    {   
        return [
            'settings' => [
                'label'       => 'Test Settings',
                'description' => 'Test settings descr',
                'class'       => 'AuthorName\PluginName\Models\Settings',
              ],
        ];
    }

Plugin's navigation registration:

    public function registerNavigation()
    {   
        return [
            'main-menu' => [
                'label'       => 'Test Menu',
                'url'         => Backend::url('AuthorName/PluginName/test'),

                'sideMenu' => [
                    'side-menu-item' => [
                        'label' => 'Settings',
                        'url' => Backend::url('AuthorName/PluginName/settings'),
                    ],
                ],
            ],
        ];
    }

Controller definition:

<?php namespace AuthorName\PluginName\Controllers;

use BackendMenu;
use Redirect;
use Request;        

class Settings extends \System\Controllers\Settings
{                       
    protected $author;
    protected $plugin;
    protected $code = 'settings'; // see registerSettings()
    protected $mainMenuId = 'main-menu'; // see registerNavigation()
    protected $sideMenuId = 'side-menu-item'; // see registerNavigation()

    public function __construct()
    {   
        parent::__construct();
        $this->viewPath = base_path().'/modules/system/controllers/settings';

        // Extract Author and Plugin name from current class path
        list($this->author, $this->plugin) = explode('\\', get_class());

        BackendMenu::setContext(sprintf('%s.%s', $this->author, $this->plugin), $this->mainMenuId, $this->sideMenuId);
    }

    public function index()
    {   
        $url = sprintf('%s/update/%s/%s/%s', Request::url(), $this->author, $this->plugin, $this->code);

        return Redirect::to($url);
    }
}

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?