Jump to content

Recommended Posts

Posted

Hi folks

I was just wondering what the best way to handle multiple key/value pairs in a module config would be?

For example, in a few modules I will likely need to enter information in a text field and then select an associated page, but up to as many times as the administrator requires.

The simplest way would be to use a textarea and go the CSV route and type the page paths manually, so:

option1,/path/to/page/
option2,/path/to/another/page/

Whilst this way of doing things is fine, I wonder if there's another way (doesn't matter that it essentially gets saved as a CSV behind the scenes - it would just be nice to make the config simpler to use and remove the chance of typos in paths :)

I'm going to have a crack at it with some jQuery as I've just had an idea, but if anyone has any other suggestions I'm all ears :)

Posted

Pete, you can store arrays in a module config:

$data = array(
  'options' => array(
    '/path/to/page/',
    '/path/to/another/page/'
    )
  );

$modules->saveModuleConfigData('MyModuleName', $data); 

Of course 'options' could be an associative array too if you wanted it. 

Posted

Thanks - that will help me when I've got my jQuery goodness sorted that adds new rows of fields.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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