itGuild tables
This commit is contained in:
@ -2,8 +2,10 @@
|
||||
namespace app\controllers;
|
||||
|
||||
|
||||
use app\foo;
|
||||
use app\models\Question;
|
||||
use app\models\User;
|
||||
use Itguild\Tables\ListJsonTable;
|
||||
use kernel\Controller;
|
||||
|
||||
class UserController extends Controller{
|
||||
@ -35,7 +37,14 @@ class UserController extends Controller{
|
||||
{
|
||||
$userArr[$i++] = $user;
|
||||
}
|
||||
echo $this->twig->render('userTable.html', ['userArr' => $userArr]);
|
||||
echo $this->twig->render('user_table.html.twig', ['userArr' => $userArr]);
|
||||
|
||||
$json = new foo();
|
||||
$userArr = $json->createJsonArray(User::labels(), $userArr, "form1");
|
||||
$table = new ListJsonTable($userArr);
|
||||
$table->create();
|
||||
$table->render();
|
||||
|
||||
}
|
||||
|
||||
public function actionView($id): void
|
||||
|
46
app/foo.php
Normal file
46
app/foo.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app;
|
||||
class foo
|
||||
{
|
||||
public array $informationArray;
|
||||
|
||||
/**
|
||||
* @param array $columns
|
||||
* @param array $data
|
||||
* @return string|null
|
||||
*/
|
||||
public function createJsonArray(array $columns, array $data, string $title): ?string
|
||||
{
|
||||
if ($columns && $data) {
|
||||
$this->informationArray = [
|
||||
"meta" => [
|
||||
"title" => $title,
|
||||
"columns" => $columns,
|
||||
"perPage" => 10,
|
||||
"currentPage" => 1,
|
||||
"params" =>
|
||||
[
|
||||
"class" => "table table-bordered",
|
||||
"border" => "1"
|
||||
]
|
||||
],
|
||||
"data" => $data
|
||||
];
|
||||
return $this->toJson($this->informationArray);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $infArr
|
||||
* @return string|null
|
||||
*/
|
||||
protected function toJson(array $infArr): ?string
|
||||
{
|
||||
if ($infArr)
|
||||
return json_encode($infArr, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
return null;
|
||||
}
|
||||
}
|
@ -5,5 +5,15 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class User extends Model {
|
||||
protected $table = 'user';
|
||||
protected $fillable = ['username', 'email', 'password_hash', 'role'];
|
||||
protected $dates = ['deleted at'];
|
||||
protected array $dates = ['deleted at'];
|
||||
|
||||
public static function labels(): array
|
||||
{
|
||||
return [
|
||||
'username' => 'Логин',
|
||||
'email' => 'Email',
|
||||
'created_at' => 'Создан',
|
||||
'updated_at' => 'Обновлен'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user