afzalroq/yii2-cms

Yii2 cms extension

Installs: 1 040

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 2

Forks: 4

Open Issues: 0

Type:yii2-extension

1.0.0 2020-12-03 12:41 UTC

This package is auto-updated.

Last update: 2022-01-23 09:52:00 UTC


README

The extension allows:

  • make html blocks of html contents, files, images.
  • make collections for options like tags, categories
  • make entities for items like sliders, products, reviews, articles, pages
  • support up to 5 languages
  • support SEO meta tags
  • make multiple menu with parenting feature

Installation

  • Install with composer:
composer require afzalroq/yii2-cms "^1.0"
  • After composer install run console command for create tables:

Add to console config for auto discover migrations

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

Setup in common config file

CKEditor use Elfinder plugin for save files and images. Refer Elfinder readme for proper configuration

  • Language indexes related with database columns.
  • Admin panel tabs render by array values order
  • For Items, Options and Menu must be isset common\models\User model
'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
        // 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',
        ]
    ],
]

By default uses for caching component with name "cache". Config as belove:

'components' => [
    'cache' => [
        'class' => 'yii\caching\FileCache',
        'cachePath' => Yii::getAlias('@frontend') . '/runtime/cache'
    ],
]
  • In admin panel open management via link:
/cms/home/index

Added Laravels dd() (dump and die) method

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

Examples

TODO

  • test
  • Copy from extension root directory example widgets for frontend integration

Usage

Use in frontend CController extending CMSController for proper menu generated links work

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 getter

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

Item Getters

\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

Return File URI

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

Return Datetime with specified format

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

Return image URI by specified operation(default cropResize)

View all image operations & examples from documentation

// 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 Getters

 $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

Option and Items searches

 \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