Homepage
Main navigation
Main content
Additional information
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
Winter CMS resources and help articles
Simple and to the point. Optimized by the community.
×
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
Edit trick
Changes will be published after manual review
Title
Give your trick a describing title. Do
not
start with «How to...».
Your trick
Keep it short and concise! Markdown is supported.
1. [Create your Settings plugin as usual](https://wintercms.com/docs/v1.2/docs/plugin/settings#settings-link-registration), but use the url instead of class property at the registerSettings method. 2. Create a controller: Settings.php: ``` <?php namespace Author\Plugin\Controllers; use Backend\Classes\Controller; use Backend; use Redirect; use BackendMenu; use System\Classes\SettingsManager; use Winter\Storm\Router\Helper as RouterHelper; class Settings extends Controller { public $implement = [ \Backend\Behaviors\FormController::class ]; public $formConfig = [ 'name' => 'Settings', 'form' => "$/author/plugin/models/settings/fields.yaml", 'modelClass' => 'Author\Plugin\Models\Settings', 'defaultRedirect' => 'author/plugin/settings/update/:id', ]; public function __construct() { parent::__construct(); BackendMenu::setContext('Winter.System', 'system', 'settings'); SettingsManager::setContext('Author.Plugin', 'settings'); } /* NEEDED FOR SETTINGS PAGE COMBINED WITH AJAX EVENTS */ public function index() { return $this->update(); } public function create() { return $this->update(); } public function update($id=null) { if (is_null($id)) { $model = $this->formCreateModelObject(); $model = $model->firstOrCreate(['item' => $model->settingsCode]); $redirectUrl = RouterHelper::replaceParameters($model, $this->formGetRedirectUrl('update', $model)); return Backend::redirect($redirectUrl); } return parent::update($id); } /* END */ public function onMyFunction() { } } ``` 3. Create settings folder in controllers folder with update.htm: ``` <?php Block::put('breadcrumb') ?> <ul> <li><?= e($this->pageTitle) ?></li> </ul> <?php Block::endPut() ?> <?= Form::open(['class' => 'layout']) ?> <div class="layout-row"> <?= $this->formRender() ?> </div> <div class="form-buttons"> <div class="loading-indicator-container"> <button type="submit" data-request="onSave" data-request-data="redirect:0" data-hotkey="ctrl+s, cmd+s" class="btn btn-primary"> <u>S</u>ave </button> </div> </div> <?= Form::close() ?> ``` Now you can call your Ajax functions.
References
Add additional online resources to your trick
×
Name
URL
+ Add reference
Topics
If your trick fits more than one topic select multiple. Select at least one.
Backend
Plugin Development
CMS
Twig
Themes
Deployment
Tags
You can use existing tags or create new ones. Add at least one.
Submit for review
Cancel
We use cookies to measure the performance of this website. Do you want to accept these cookies?
Accept
Decline