PHP code example of simpleteam / craft-toolkit

1. Go to this page and download the library: Download simpleteam/craft-toolkit library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

simpleteam / craft-toolkit example snippets


Craft::$app->options->set('my_key', 'my_value');

// Store complex data (automatically will be JSON encoded)
Craft::$app->options->set('user_preferences', [
    'theme' => 'dark',
    'language' => 'en',
    'notifications' => true
]);

$value = Craft::$app->options->get('my_key');

// With default value
$theme = Craft::$app->options->get('my_key', 'some_default_value');

if (Craft::$app->options->exists('my_key')) {
    // Option exists
}

// Or use the alias
if (Craft::$app->options->has('my_key')) {
    // Option exists
}

Craft::$app->options->delete('my_key');

$allOptions = Craft::$app->options->getAll();

// Get only autoload options
$autoloadOptions = Craft::$app->options->getAll(true);

Craft::$app->options->setMultiple([
    'option1' => 'value1',
    'option2' => 'value2',
    'option3' => ['complex' => 'data']
]);