PHP code example of locustv2 / yii2-json-data-behavior

1. Go to this page and download the library: Download locustv2/yii2-json-data-behavior 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/ */

    

locustv2 / yii2-json-data-behavior example snippets


public function behaviors()
{
    return [
        'class' => \locustv2\behaviors\JsonDataBehavior::className(),
        'dataAttribute' => 'hotel_data',
    ];
}

$model = Hotel::find()->one();

var_dump($model->getData('rooms')); // assume it returns a list of rooms
var_dump($model->getData('rooms.0.price')); // to get rooms data

$model->setData('ratings', [
    '5star' => ['count' => 100],
    '4star' => ['count' => 200],
    '3star' => ['count' => 20],
    '2star' => ['count' => 75],
    '1star' => ['count' => 50],
]);

var_dump($model->getData('ratings.3star.count')); // returns 20