JimBurnett Posted November 26, 2018 Posted November 26, 2018 Hello, is there a good example or tutorial for how a custom application can access settings? I created an admin module for my application ("em") in applications\em\modules\admin\em\settings.php. When I navigate to it on the /admin/ dashboard, the page will load, but I get an exception when I try to save. Thanks in advance for any help. Here's the exception: Here is settings.php. <?php namespace IPS\em\modules\admin\em; /* To prevent PHP errors (extending class does not exist) revealing path */ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) ) { header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' ); exit; } /** * settings */ class _settings extends \IPS\Dispatcher\Controller { /** * Execute * * @return void */ public function execute() { parent::execute(); } /** * ... * * @return void */ protected function manage() { // This is the default method if no 'do' parameter is specified //<?php \IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('settings'); $form = new \IPS\Helpers\Form; //$form->add( new \IPS\Helpers\Form\Text( 'plugin_example_setting', \IPS\Settings::i()->plugin_example_setting ) ); $form->add( new \IPS\Helpers\Form\Text( 'access_server' ),\IPS\Settings::i()->access_server); if ( $values = $form->values() ) { $form->saveAsSettings(); return TRUE; } //return $form; \IPS\Output::i()->output = $form; } // Create new methods with the same name as the 'do' parameter which should execute it }
Ryan Ashbrook Posted November 26, 2018 Posted November 26, 2018 Have you added the setting via the Developer Center? ACP > Applications > Developer Center (in the menu next to your app) > Settings. It must be added there before you can use it.
JimBurnett Posted November 26, 2018 Author Posted November 26, 2018 Thank you for the response. Yes I did add it there. I see it in the developer center and when I make changes in the developer center I observe that it correctly updates the applications\em\data\settings.json file.
teraßyte Posted November 26, 2018 Posted November 26, 2018 You have ) in the wrong place in your code after 'access_server', move it at the end: $form->add( new \IPS\Helpers\Form\Text('access_server',\IPS\Settings::i()->access_server) );
bfarber Posted November 26, 2018 Posted November 26, 2018 35 minutes ago, JimBurnett said: Thank you for the response. Yes I did add it there. I see it in the developer center and when I make changes in the developer center I observe that it correctly updates the applications\em\data\settings.json file. The question was though, did you add it through the developer center (as opposed to, say, adding it directly to a settings.json file)? The reason asked is because when you add the setting through the developer center it should also get added to the core_sys_conf_settings database table. The error you are getting indicates this setting key is not present in the table.
JimBurnett Posted November 26, 2018 Author Posted November 26, 2018 33 minutes ago, teraßyte said: You have ) in the wrong place in your code after 'access_server', move it at the end: $form->add( new \IPS\Helpers\Form\Text('access_server',\IPS\Settings::i()->access_server) ); Thank you! I revised the code per your suggestion. Unfortunately I'm still getting the same error. Any idea what else I could be missing? 3 minutes ago, bfarber said: The question was though, did you add it through the developer center (as opposed to, say, adding it directly to a settings.json file)? The reason asked is because when you add the setting through the developer center it should also get added to the core_sys_conf_settings database table. The error you are getting indicates this setting key is not present in the table. Good thought. I am not sure the order of operations that I did. I will try deleting it & re-adding it.
JimBurnett Posted November 26, 2018 Author Posted November 26, 2018 You are a super genius. I deleted it through the developer center & added a new one, named 'em_access_server' through the developer center. I no longer get an exception & the setting appears to save. Thank you for following up & reading between the lines. Your understanding of the error has saved me time & frustration! Jim
Aiwa Posted November 26, 2018 Posted November 26, 2018 Furthermore, settings are common for all apps / plugins, keys should be UNIQUE to your application. 'access_server', with no prefix, is quite generic and runs a higher probabity of overlap.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.