Topic Closed
derek
16 Posts

Hi everyone,

I'm trying to develop my first plugin.  I'm building an Admin page to store settings/config for the plugin.  I'm storing the config in an array, and going to save it to a file.  I have discovered the gpFiles::SaveArray function which I'm using to save the array.

Once the array has been saved in the config file, what's the best way to retrieve it?  Just include the config file in my plugin or is there a similar function to load an array from a file?

Thanks in advance for your help! :)

4 years ago#9095

a2exfr
242 Posts
26.3K Downloads
2 Themes
10 Plugins

Hello

include the config file in my plugin

thats enough in most cases, just do not forget to check file existens and so on

something like this

 global                   $addonPathData;

    $dataFile            = $addonPathData.'/mydata.php'; // your file name
    
    if(  file_exists( $dataFile ) )    {
        include_once $dataFile;
            }

    if (isset($myarray)) {
     
   // use your array
    
    } else {

// may  set some default values

}

 

 

4 years ago#9096

Josh S.
2K Posts
283K Downloads
16 Themes
18 Plugins

I would actually recommend not using the SaveArray() method. Since version 4.4, SaveData() can be used like so:

global $addonPathData;
$file = $addonPathData.'/data.php';

//saving data
$data = array('your'=>'array','of'=>'data');
if( !gpFiles::SaveData($file, 'data', $data) ){
    //... warn user data didn't save
}


//retrieve stored data
$data = gpFiles::Get($file,'data');

 

4 years ago#9103

derek
16 Posts

Awesome, thanks Josh. This is exactly what I was after. 

Is there somewhere that documents the gpFiles methods and how to use them? I've pulled together a list of them all, but not sure what parameters they all require. 

4 years ago#9114

Josh S.
2K Posts
283K Downloads
16 Themes
18 Plugins
Sorry, the docs are a bit out of date. The code itself is pretty well commented which gives you info about the parameters.
4 years ago#9127

derek
16 Posts

Thanks. Starting to pick my way through the source files and piece things together.

Is it possible to contribute to the documentation?  Happy to make some updates as I go.

4 years ago#9203

Josh S.
2K Posts
283K Downloads
16 Themes
18 Plugins

Absolutely!

Our current docs have edit links at the bottom of each page.

4 years ago#9212

derek
16 Posts
Brilliant! I'll try and add to this as I go. Thanks :)
4 years ago#9215

Topic Closed

 

News

elFinder 2.1.50 in Upcoming Release
12/28/2019

A new release for Typesetter is in the works with a lot of improvements including the ... Read More

Typesetter 5.1
8/12/2017

Typesetter 5.1 is now available for download. 5.1 includes bug fixes, UI/UX improvements, ... Read More

More News

creisi productions

Dienstleistungen von creisi productions, Luzern (Schweiz): * Konzeption, Planung und Erstellung Ihres Internet-Auftritts * Betreuung und Aktualisierung/Pflege Ihrer Website * ...

Find out more about our Provider Spotlight

Log In

  Register