Jump to content

using IPS\Settings for custom application


JimBurnett

Recommended Posts

Posted

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:

image.thumb.png.c4e1dc6767492bdfcd98726dcb101540.png

 

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
 
}

 

Posted

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.

 

image.thumb.png.3570d57a189395858b97a63cf2e35828.png

Posted
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.

 

image.thumb.png.3570d57a189395858b97a63cf2e35828.png

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.

Posted
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.

Posted

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

image.png

Posted

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...