Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Description


Core\Storage storage()


Storage allows you to store information in the DB, without the need to create custom database tables on a clients set.

Examples


<?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 . ',';
   }
});

Methods


MethodDescriptionUsageReturns

get(string $var)

 


$var

Provide the HTTP request key

Returns the HTTP request value.

/**
 * URL Example: /foo?hello=1
 */
if (request()->get('hello')) {
   echo "Hello!";
}

HTTP request value on success, null on failure.

This supports all incoming HTTP
requests (e.g. GET, POST, DELETE etc...) 

isPost()

Checks to see if a form has been posted.

if (request()->isPost()) {

}

true on success, false on failure.

This method only checks POST requests.

segment(int $number)

 


$number

Provide the segment number
of the URL. 

Returns URL segment based on the
forward slash. 

 

/**
 * URL Example: /foo/bar
 */
echo request()->segment(1); // Prints foo
echo request()->segment(2); // Prints bar
Segment value on success, null on failure.
  • No labels