PHP code example of dmstr / yii2-themed-view-path-behavior

1. Go to this page and download the library: Download dmstr/yii2-themed-view-path-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/ */

    

dmstr / yii2-themed-view-path-behavior example snippets




namespace project\modules\admin\controllers;

use dmstr\themedViewPath\ThemedViewPathBehavior;

class SearchGroupController extends \dmstr\activeRecordSearch\controllers\SearchGroupController
{

    public function behaviors()
    {
        $behaviors = parent::behaviors();

        $behaviors['themedViewPath'] = [
            'class' => ThemedViewPathBehavior::class,
            'pathMap' => '@vendor/dmstr/yii2-active-record-search/src/views/search-group',
            'useAsBasePath' => false,
        ];

        return $behaviors;

    }

    public function actionCreate()
    {
        return "Action is not available in this context";
    }

    public function actionDelete($id)
    {
        return "Action is not available in this context";
    }
}



namespace project\modules\admin\controllers;

use dmstr\themedViewPath\ThemedViewPathBehavior;
use yii\web\Controller;

class BaseController extends Controller
{
    #....
    public function behaviors()
    {
        $behaviors = parent::behaviors();

        $behaviors['themedViewPath'] = [
            'class' => ThemedViewPathBehavior::class,
            'pathMap' => '@project/modules/cruds/views',
            'useAsBasePath' => true,
        ];

        return $behaviors;

    }
    #....



namespace project\modules\admin\controllers;

use dmstr\themedViewPath\ThemedViewPathBehavior;
use project\components\ApplicationHelper;
use yii\web\Controller;

class BaseController extends Controller
{
    #....
    public function behaviors()
    {
        $behaviors = parent::behaviors();

        $behaviors['themedViewPath'] = [
            'class' => ThemedViewPathBehavior::class,
            'pathMap' => [
                '@project/modules/cruds/views',
            ],
            'subDirs' => [
                ApplicationHelper::brand(),
            ],
            'useAsBasePath' => true,
        ];

        return $behaviors;

    }
    #....



namespace app\modules\cruds;

use dmstr\themedViewPath\ThemedViewPathBehavior;

/**
 *  module definition class.
 */
class Module extends \yii\base\Module
{
    #....
    public function behaviors()
    {
        $behaviors = parent::behaviors();

        $behaviors['themedViewPath'] = [
            'class' => ThemedViewPathBehavior::class,
            'pathMap' => $this->getViewPath() . '-extended',
            'pathOrder' => ThemedViewPathBehavior::MAP_PREPEND,
        ];

        return $behaviors;

    }
    #....

}

[
    '/app/project/src/modules/cruds/views' => [
        0 => '/app/project/src/modules/cruds/views-extended'
        1 => '/app/project/src/modules/cruds/views'
    ]
]



namespace project\modules\frontend\widgets\careerportal;

use dmstr\themedViewPath\ThemedViewPathBehavior;
use project\components\ApplicationHelper;

class LatestJobs extends \yii\base\Widget
{

    #....
    public function behaviors()
    {
        $behaviors = parent::behaviors();

        $behaviors['themedViewPath'] = [
            'class' => ThemedViewPathBehavior::class,
            'subDirs' => [
                ApplicationHelper::brand(),
            ],
        ];

        return $behaviors;

    }
    #....
}