PHP code example of yii2tech / admin

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

    

yii2tech / admin example snippets


namespace app\controllers;

use yii\web\Controller;

class ItemController extends Controller
{
    public function actions()
    {
        return [
            'index' => [
                'class' => \yii2tech\admin\actions\Index::class,
                'newSearchModel' => function () {
                    return new ItemSearch();
                },
            ],
            'view' => [
                'class' => \yii2tech\admin\actions\View::class,
            ],
            'create' => [
                'class' => \yii2tech\admin\actions\Create::class,
            ],
            'update' => [
                'class' => \yii2tech\admin\actions\Update::class,
            ],
            'delete' => [
                'class' => \yii2tech\admin\actions\Delete::class,
            ],
        ];
    }

    public function findModel($id)
    {
        if (($model = Item::findOne($id)) !== null) {
            return $model;
        }
        throw new NotFoundHttpException('The requested page does not exist.');
    }

    public function newModel()
    {
        return new Item();
    }
}

return [
    //....
    'modules' => [
        // ...
        'gii' => [
            'class' => yii\gii\Module::class,
            'generators' => [
                'adminMainFrame' => [
                    'class' => yii2tech\admin\gii\mainframe\Generator::class
                ],
                'adminCrud' => [
                    'class' => yii2tech\admin\gii\crud\Generator::class
                ]
            ],
        ],
    ]
];

return [
    'components' => [
        'i18n' => [
            'translations' => [
                'yii2tech-admin' => [
                    'class' => yii\i18n\PhpMessageSource::class,
                    'basePath' => '@yii2tech/admin/messages',
                ],
                // ...
            ],
        ],
        // ...
    ],
    // ...
];

php composer.phar