PHP code example of zumba / swivel-cake

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

    

zumba / swivel-cake example snippets


CakePlugin::load('Swivel', ['bootstrap' => true]);



$config = [
    'Swivel' => [
        'Cookie' => [
            'enabled' => true,
            'name' => 'Swivel_Bucket',
            'expire' => 0,
            'path' => '/',
            'domain' => env('HTTP_HOST'),
            'secure' => false,
            'httpOnly' => false
        ],
        'BucketIndex' => null,
        'LoaderAlias' => 'SwivelManager',
        'Logger' => null,
        'Metrics' => null,
        'ModelAlias' => 'Swivel.SwivelFeature',
    ]
];



// Saving bucket 1 for internal testing
$bucketIndex = isset($_COOKIE['Swivel_Bucket']) ? $_COOKIE['Swivel_Bucket'] : mt_rand(2, 10);

$config = [
    'Swivel' => [
        'BucketIndex' => $bucketIndex
    ]
];


App::uses('AppModel', 'Model');
App::uses('SwivelModelInterface', 'Swivel.Lib');

class SwivelFeature extends AppModel implements SwivelModelInterface {
    public $useTable = false;

    public function getMapData()
    {
        // @todo Load data from some source
        // @todo Format this data in a KEY/VALUE array, where KEY is the feature
        // and VALUE is the buckets in an array format, ie [1, 2, 3]
        // @todo Return the formatted data
        return [
            'FeatureA' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
            'FeatureB' => [1, 2, 3],
            'FeatureC' => [2, 4, 6, 8, 10],
        ];
    }
}



class UsersController extends AppController
{
    public $components = ['Swivel.Swivel'];
    public $uses = ['User', 'MyCoolWidget'];

    public function index()
    {
        $this->set('users', $this->User->find(/* ... */));
        $this->Swivel->invoke('MyCoolWidget', function() {
            return $this->set('widget', $this->MyCoolWidget->find(/* ... */));
        });
    }

    public function view($id = null)
    {
        $this->Swivel->forFeature('Redesign')
            ->addBehavior('userView', [$this, 'renderNewView'], [$id])
            ->defaultBehavior([$this, 'renderOldView'], [$id])
            ->execute();
    }

    protected function renderOldView($id)
    {
        // @todo implement
        $this->render('oldView');
    }

    protected function renderNewView($id)
    {
        // @todo implement
        $this->render('newView');
    }
}