PHP code example of afzalroq / yii2-cms

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

    

afzalroq / yii2-cms example snippets


'controllerMap' => [
    'migrate' => [
        'class' => MigrateController::class,
        'autoDiscover' => true,
        'migrationPaths' => [
            '@vendor/afzalroq/yii2-cms/migrations'
        ],
    ],
]

'modules' => [
    'cms' => [ // don`t change module key
        'class' => '@afzalroq\cms\Module',
        // storage
        'path' => $params['storageRoot'], // dirname(__DIR__, 2) . '/storage'
        'host' => $params['storageHostInfo'], // 'https://site.example'    
        'cache' => 'cache', // default cache component name
        'cacheDuration' => 3600, // default cache duration 3600 second
        'optimized' => false, // set true for get items with options as $item->o 
        // images
        'imageOperation' => 'cropResize',
        'imageBackground' => 'transparent',
        'imageXPos' => 'center',
        'imageYPos' => 'center',
        'fallback' => $params['storageRoot'] . '/fallback.png',
        'watermark' => $params['storageRoot'] . '/logo.png',
        // i18n
        'languages' => [
            'ru' => [
                'id' => 0, // must start from 0 up to 4
                'name' => 'English',
            ],
            'en' => [
                'id' => 1,
                'name' => 'Русский',
            ],
            'uz' => [
                'id' => 2,
                'name' => 'O`zbek tili',
            ],
        ],
        // for add to menu controller actions
        'menuActions' => [
            '' => 'Home',
            'site/contacts' => 'Contacts',
        ]
    ],
]

'components' => [
    'cache' => [
        'class' => 'yii\caching\FileCache',
        'cachePath' => Yii::getAlias('@frontend') . '/runtime/cache'
    ],
]

/cms/home/index

$array = ['a', 'b'];
dd($array);

class CController extends CMSController {
    
    public function actionCollection(string $c)
    {
    }

    public function actionOption(string $c, string $o)
    {
    }

    public function actionEntity(string $e)
    {
    }

    public function actionItem(string $e, int $i)
    {
    }
}

Unit::get('slug'); // will return data using cache

\afzalroq\cms\entities\front\OaI::getItemIdsByCollection($slug) : array // of item Ids
\afzalroq\cms\entities\front\OaI::getItemIdsByOption($slug) : array // of item Ids

 $item->getText1(); // for get Text 1
 $item->getText2(); // for get Text 2
 $item->getText3(); // for get Text 3
 $item->getText4(); // for get Text 4
 $item->getText5(); // for get Text 5
 $item->getText6(); // for get Text 6
 $item->getText7(); // for get Text 7
 

 //for to get meta description and meta keywords just use this command below:
 $item-registerMetaTags(); //it generates meta tags in your view page

 $item->getFile1(); // for get File 1
 $item->getFile2(); // for get File 2
 $item->getFile3(); // for get File 3 

 $item->getDate($format); // for get date with format like "d.m.Y H:i:s"
 

// get gallery main photo URI
$item->getGalleryPhoto(width, height, operation, background, xPos, yPos)

// get gallery photos URI
$items->getPhotos() // and use with "foreach(){}"

// item photos URI
 $item->getPhoto1(width, height, operation, background, xPos, yPos); // for get Photo 1
 $item->getPhoto2(width, height, operation, background, xPos, yPos); // for get Photo 2
 $item->getPhoto3(width, height, operation, background, xPos, yPos); // for get Photo 3

 $option->getName(); // for get Name

 $option->getContent(); // for get Content

 $option->getPhoto1(); // for get Photo 1
 $option->getPhoto2(); // for get Photo 2

 $option->getFile1(); // for get File 1
 $option->getFile2(); // for get File 2

 //for to get meta description and meta keywords just use this command below:
 $option-registerMetaTags(); //it generates meta tags in your view page

 \afzalroq\cms\entities\front\Items::getEntityItemSearchResults((array) $entitySlugs, $search); // get search results with entity and items
 
 \afzalroq\cms\entities\front\Items::getOptionItemSearchResults((array) $optionSlugs, $search); // get search results with option and items

 \afzalroq\cms\entities\front\Options::getOptionSearchResults((array) $optionSlugs, $search); // get search results with options
 
bash
php yii migrate/up --migrationPath=@vendor/afzalroq/yii2-cms/migrations