1. Go to this page and download the library: Download juneszh/alight-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/ */
juneszh / alight-admin example snippets
namespace ctr\admin;
use Alight\Admin\Auth;
use Alight\Admin\Form;
use Alight\Admin\Table;
class Test
{
public static function userTable()
{
// Check the role_id from logged in user
Auth::checkRole([1]); // Here '1' means only administrators have access
// Create the table columns and search bar
Table::column('id')->sort('ascend');
Table::column('account')->search()->sort();
Table::column('role_id')->search('select')->enum([1 => 'Administrator', 2 => 'Editor']);
Table::column('name')->search();
Table::column('email')->search();
Table::column('status')->search('select')->enum([1 => 'Enable', 2 => 'Disable']);
Table::column('create_time')->search('dateRange');
// Create the buttons
Table::button('add')->toolbar(); // Here 'toolbar()' means this button will be placed on toolbar
Table::button('edit');
Table::button('password')->danger();
// Bind the database table 'admin_user' and render table page
Table::render('admin_user');
}
}
public static function userForm()
{
// Ditto, Check the user access
Auth::checkRole([1]);
// Create the form fields
Form::create('add'); // This form will bind the 'add' button
Form::field('account')->;
Form::field('confirm_password')->database(false)->type('password')-> // Create last form for 'password' button
Form::create('password')->copy('add', ['password', 'confirm_password']);
// Bind the database table 'admin_user' and render form page
Form::render('admin_user');
}
// Here using Line charts, we support 30+ charts with AntDesign Charts
// More details please refer to : https://charts.ant.design/en/docs/api
Console::chart('Line')->config([
'xField' => 'date',
'yField' => 'value',
'height' => 200,
'data' => [
['date' => '2019-07-21', 'value' => 20],
['date' => '2019-07-22', 'value' => 14],
['date' => '2019-07-23', 'value' => 9],
['date' => '2019-07-24', 'value' => 26]
]
])->grid(['span' => 12]); // Means half the width of the grid. full of 24
Console::chart('Column')->config([
'xField' => 'date',
'yField' => 'value',
'height' => 200
])->grid(['span' => 12])->api('test/column'); // Define the path to the API
public static function columnData()
{
// Check the user access
Auth::checkRole([1]);
$data => [
['date' => '2019-08-28', 'value' => 20],
['date' => '2019-08-29', 'value' => 19],
['date' => '2019-08-30', 'value' => 6],
['date' => '2019-08-31', 'value' => 9]
];
// Respond using the built-in json format api
Alight\Response::api(0, null, ['data' => $data]);
}