PHP code example of cakesuit / option

1. Go to this page and download the library: Download cakesuit/option 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/ */

    

cakesuit / option example snippets



Router::plugin(
    'Cakesuit/Option',
    ['path' => '/cakesuit'],
    function (RouteBuilder $routes) {
        
        // List all
        $routes->connect(
            'options', 
            [
                'controller' => 'Options', 
                'action' => 'index'
            ]
        );
        
        // Add
        $routes->connect(
            'options', 
            [
                'controller' => 'Options', 
                'action' => 'add'
            ]
        );
        
        // Edit
        $routes->connect(
            'options/edit/:id', 
            [
                'controller' => 'Options', 
                'action' => 'edit', 
                [
                    'id' => '[0-9]+',
                    'pass' => ['id']
                ]
            ]
        );

        // Show
        $routes->connect(
            'options/view/:id', 
            [
                'controller' => 'Options', 
                'action' => 'view', 
                [
                    'id' => '[0-9]+',
                    'pass' => ['id']
                ]
            ]
        );
        
        // Delete
        $routes->connect(
            'options/delete/:id', 
            [
                'controller' => 'Options', 
                'action' => 'delete', 
                [
                    'id' => '[0-9]+',
                    'pass' => ['id']
                ]
            ]
        );
        
    }
);


// Load the Model if necessary
$this->loadModel('Options');

// Fetch all data marked autoload
$options = $this->Options->find('autoload');
echo $options->site_name; // = 'My Blog'
echo $options->site_description; // = 'Use CakeSuit/Option for advance settings'
echo $options->analytics_ua; // = null (this value does not exist)


// Load the Model if necessary
$this->loadModel('Cakesuit/Option.Options');
$options = $this->Options->find('keys', [
    'keys' => ['analytics_ua', 'site_description']
]);
echo $options->site_name; // = null
echo $options->site_description; // = 'Use CakeSuit/Option for advance settings'
echo $options->analytics_ua; // = 'UA-XXXXXX'


// Load the Model if necessary
$this->loadModel('Cakesuit/Option.Options');

$options = $this->Options->find('keys', [
    'keys' => ['no_exists_value']
]);
$options->isEmpty(); // = true


// Load the Model if necessary
$this->loadModel('Cakesuit/Option.Options');

$options = $this->Options->find('autoload');
echo $options->count(); // = 2