PHP code example of phact-cmf-modules / admin

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

    

phact-cmf-modules / admin example snippets


class Book extends Model
{
    public static function getFields()
    {
        return [
            'name' => [
                'class' => CharField::class,
                'label' => 'Наименование'
            ],
        ];
    }
}

class BookAdmin extends Admin
{
    public function getSearchColumns()
    {
        return ['name'];
    }

    public function getModel()
    {
        return new Book();
    }

    public static function getName()
    {
        return 'Книги';
    }

    public static function getItemName()
    {
        return 'Книга';
    }
}

class BookAdmin extends Admin
{
...
    public function getForm()
    {
        return new BookAdminForm();
    }
...
}

class BookAdmin extends Admin
{
...
    public function getForm()
    {
        return new BookAdminCreateForm();
    }

    public function getUpdateForm()
    {
        return new BookAdminUpdateForm();
    }
...
}

class Release extends Model
{
    public static function getFields()
    {
        return [
            'book' => [
                'class' => ForeignField::class,
                'modelClass' => Book::class,
                'label' => 'Книга'
            ],
            'year' => [
                'class' => CharField::class,
                'label' => 'Год'
            ],
            'position' => [
                'class' => PositionField::class,
                'editable' => false,
                'default' => 0,
                'relations' => [
                    'book'
                ]
            ]
        ];
    }

    public function __toString()
    {
        return (string) $this->year;
    }
}

class ReleaseAdmin extends Admin
{
    public static $ownerAttribute = 'book';

    public function getSearchColumns()
    {
        return ['year'];
    }

    public function getModel()
    {
        return new Release();
    }

    public static function getName()
    {
        return 'Издания';
    }

    public static function getItemName()
    {
        return 'Издание';
    }
}

class BookAdmin extends Admin
{
...
    public function getRelatedAdmins()
    {
        return [
            'releases' => ReleaseAdmin::class
        ];
    }
...
}