PHP code example of wdmg / yii2-content

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

    

wdmg / yii2-content example snippets


        if ($block = Yii::$app->content->get(1)) {
            
            // Raw output
            echo $block['adress']; // where `adress` as filed name
            echo $block['phone']; // where `phone` as filed name
            echo $block['email']; // where `email` as filed name
            
            // With ListView and ArrayDataProvider
            $dataProvider = new \yii\data\ArrayDataProvider([
                'allModels' => $block
            ]);
            echo yii\widgets\ListView::widget([
                'dataProvider' => $dataProvider,
                'layout' => '<dl class="dl-horizontal">{items}</dl>{pager}',
                'itemView' => function($data, $key, $index, $widget) {
                    return "<dt>" . $key . "</dt>" . "<dd>" . $data . "</dd>";
                }
            ]);
            
        }
    

        if ($list = Yii::$app->content->get('our-team', 'ru-RU')) {
            
            // Raw output
            foreach ($list as $row) {
                echo $row['first_name']; // where `first_name` as filed name
                echo $row['last_name']; // where `last_name` as filed name
            }
            
            // With GridView and ArrayDataProvider
            $dataProvider = new \yii\data\ArrayDataProvider([
                'allModels' => $list
            ]);
            echo \yii\grid\GridView::widget([
                'dataProvider' => $dataProvider,
            ]);
            
        }
    

        echo Nav::widget([
        'options' => ['class' => 'navbar-nav navbar-right'],
            'label' => 'Modules',
            'items' => [
                Yii::$app->getModule('content')->dashboardNavItems(),
                ...
            ]
        ]);