Core\Storage storage()
Storage allows you to store information in the DB, without the need to create custom database tables on a clients set.
<?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 . ','; } }); |
Method | Description | Usage | Returns | |
---|---|---|---|---|
get(string $var)
$var Provide the HTTP request key | Returns the HTTP request value. |
| HTTP request value on success, null on failure. This supports all incoming HTTP | |
isPost() | Checks to see if a form has been posted. |
| true on success, false on failure. This method only checks POST requests. | |
segment(int $number)
$number Provide the segment number | Returns URL segment based on the
|
| Segment value on success, null on failure. |