storePluginData

The method $this->storePluginData($filename, $data, $method = NULL) is used to store data for the plugin. It creates a folder with the name of the plugin inside the data folder and stores the provided data into the specified file.

  • @param: (string) $filename. The full filename with filetype (e.g., "data.txt").
  • @param: (string|array) $data. The data to be stored.
  • @param: (string) $method. Optional. A method to transform the data into a writable format (e.g., serialize or json_encode). Defaults to null if not provided.
  • @return: (true) Returns true if the data is successfully stored. (string) Returns an error message if an error occurs during the storage process.

Example Usage

<?php

namespace Plugins\Myplugin;

use \Typemill\Plugin;

class Myplugin extends Plugin
{
    ...

    public function myFunction()
    {
        // Storing string data
        $this->storePluginData('data.txt', 'Some text data');

        // Storing array data with serialization
        $this->storePluginData('data.json', ['key' => 'value'], 'serialize');
    }
}