Download the PHP package dd/evolutioncms-snippets-ddstash without Composer
On this page you can find all versions of the php package dd/evolutioncms-snippets-ddstash. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dd/evolutioncms-snippets-ddstash
More information about dd/evolutioncms-snippets-ddstash
Files in dd/evolutioncms-snippets-ddstash
Package evolutioncms-snippets-ddstash
Short Description Save data as JSON or QueryString, then extend if needed and use it later without database queries.
License
Homepage https://code.divandesign.biz/modx/ddstash
Informations about the package evolutioncms-snippets-ddstash
(MODX)EvolutionCMS.snippets.ddStash
Save data as JSON or Query string, then extend if needed and use it later without database queries.
Requires
- PHP >= 5.6
- (MODX)EvolutionCMS >= 1.1
- (MODX)EvolutionCMS.libraries.ddTools >= 0.49.1
Documentation
Installation
Manually
1. Elements → Snippets: Create a new snippet with the following data
- Snippet name:
ddStash. - Description:
<b>1.3</b> Save data as JSON or QueryString, then extend if needed and use it later without database queries.. - Category:
Core. - Parse DocBlock:
no. - Snippet code (php): Insert content of the
ddStash_snippet.phpfile from the archive.
2. Elements → Manage Files
- Create a new folder
assets/snippets/ddStash/. - Extract the archive to the folder (except
ddStash_snippet.php).
Using (MODX)EvolutionCMS.libraries.ddInstaller
Just run the following PHP code in your sources or Console:
- If
ddStashis not exist on your site,ddInstallerwill just install it. - If
ddStashis already exist on your site,ddInstallerwill check it version and update it if needed.
Parameters description
-
save- Desctription: Data to save in stash. Nested objects are supported too, see examples below.
- Valid values:
stringJsonObject— as JSONstringHjsonObject— as HJSONstringQueryFormated— as Query string- It can also be set as a native PHP object or array (e. g. for calls through
$modx->runSnippet):arrayAssociativeobject
- Default value: —
-
save_extendExisting- Desctription: Extend an existing object instead of overwriting it.
- Valid values:
01
- Default value:
0
-
save_extendExistingWithEmpty- Desctription: Overwrite fields with empty values (see examples below).
The following values are considered to be empty:""— an empty string[]— an empty array{}— an empty objectnull
- Valid values:
01
- Default value:
1
- Desctription: Overwrite fields with empty values (see examples below).
-
get- Desctription: Data key for getting from stash.
- Valid values:
string - Default value: —
-
get_tpl-
Desctription: Output template.
Available placeholders:
[+snippetResult+]— data from stash
- Valid values:
stringChunkNamestring— use inline templates starting with@CODE:
- Default value:
'@CODE:[+snippetResult+]'
-
storage- Desctription: Data storage.
- Valid values:
'post'—$_POST'session'—$_SESSION
- Default value:
'post'
Examples
Save some data
Get saved data
You can get field value in any depth
Returns someValue.
Returns John.
Returns Alice.
Also you can get objects in JSON
If field value is object or array, it will be returned in JSON format.
Get first John child
Returns:
Get all John children:
Returns:
Get all data about John
Returns:
Save: Extend an existing object instead of overwriting it (&save_extendExisting=`1`)
First you save some object:
Then if you just save object with the same key (userData):
The snippet will overwrite previous saved object completely:
Returns:
So, if you want to extend the first object just use the save_extendExisting parameter:
In this case the snippet will recursive extend the first object with the data from the second:
Returns:
Save: Extend without overwriting fields with empty values (&save_extendExistingWithEmpty=`0`)
By default, empty field values (e. g. '') are treated as other values and will replace non-empty ones.
Returns:
Empty lastName from the second object replaced non-empty lastName from the first.
If you want to ignore empty values, just use save_extendExistingWithEmpty == 0:
Returns: