Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted November 26, 20186 yr 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 }
November 26, 20186 yr 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.
November 26, 20186 yr Author 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.
November 26, 20186 yr 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) );
November 26, 20186 yr 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.
November 26, 20186 yr Author 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.
November 26, 20186 yr Author 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
November 26, 20186 yr 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.
Archived
This topic is now archived and is closed to further replies.