PHP code example of sergeykoz / yii2-livecontent

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

    

sergeykoz / yii2-livecontent example snippets


return [
    'bootstrap' => ['livecontent'],
    'modules' => [
        'livecontent' => [
            'class' => 'ssoft\livecontent\Module',
            //'accessRules' => [[
            //    'allow' => true,
            //    'verbs' => ['POST']
            //]],
            //'editorOptions' => [
            //    'clientOptions'=>[
            //        'rows' => 6,
            //        'autoParagraph'=>false 
            //    ],
            //    'preset' => 'full',
            //    'autoParagraph' => true
            //]
        ],
        ...
    ],
    ...
];

return [
    'controllerMap' => [
        'migrate' => [
            'class' => 'yii\console\controllers\MigrateController',
            'migrationNamespaces' => [
                'ssoft\livecontent\migrations'
            ],
        ],
    ],
];

php yii migrate --migrationPath=@vendor/sergeykoz/yii2-livecontent/src/migrations


use ssoft\livecontent\Content;

...

/*
You should replace parts of content which needs to be dynamic with calling of methods:
Content::text
Content::textarea
Content::html
Content::block

This mehtods need two arguments except of Content::block.

place -  uses for identification of the content place. You have to specify a unique key for current view file. You can insert language prefix for multilanguage applications.

isAllow - a flag which allow to show edit element on the page. You can use different cases for the argument. For basic application a case which allow to change content only for logged user is !Yii::$app->user->isGuest. For applications based on RBAC access you can use \Yii::$app->user->can('admin')

blockLogic - the argument uses just for Content::block method which consists HTML template and fields to the template.
*/


echo Content::text('text-id-'.\Yii::$app->language, !Yii::$app->user->isGuest);

...

echo Content::textarea('textblock-id', !Yii::$app->user->isGuest); // allowed to logged user

...

echo Content::html('formatted-text-id', \Yii::$app->user->can('admin')); // allowed for RBAC role  admin

...

$block=[
    'template' => "<div class=\"col-lg-4\">{edit}
        <h2>{head}</h2>
        {description}
        {show_link on}<p><a class=\"btn {button}\" href=\"{link is null}#{/link is null}{link is not null}{link}{/link is not null}\">{caption}</a></p>{/show_link on}
    </div>",               
    'rules'=> [
        'edit'=>['type'=>'editcontrol',],              
        'head' => ['name' => 'Title', 'type' => 'text', '