Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Our storage function allows you to store information in the DB, without the need to create custom database tables on a clients set. Its based on a key/value system that allows for custom queries and ordering plus the ability to set and return multiple values for a specific key.

 

Info
titleNotice

The storage system is not a cache. All data sets are permanent, unless deleted. Use the cache function if you wish to simply cache data.

 

Examples

...

Code Block
languagephp
<?php

route('/foo', function() {

   /**
    * Set a string value "bar" in the DB using the key "foo"
    */
   storage()->set('foo', 'bar');

   // Print the value for "foo"
   $object = storage()->get('foo');

   echo $object->value;



   /**
    * Storing arrays
    */
   storage()->set('foo_array', [
      'hello' => 'world'
   ]);

   // Print the value for "foo_array"
   $object = storage()->get('foo_array');

   // Prints the object
   print_r($object->value);

   // Print the "hello" value in our array, which will output "world"
   echo $object->value->hello;



   /**
    * Storing multiple values
    */
   storage()->set('multiple', '1');
   storage()->set('multiple', '2');
   storage()->set('multiple', '3');

   // Get all objects based on key
   $objects = storage()->all('multiple');
   foreach ($objects as $object) {
      // Will print 1,2,3
      echo $object->value . ',';
   }
});

...