45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
namespace App\Controllers\Admin;
|
|
|
|
use App\Models\Page;
|
|
|
|
class PageController extends AdminController
|
|
{
|
|
public function index()
|
|
{
|
|
return $this->view('admin/pages', [
|
|
'pages' => (new Page())->all(),
|
|
'seg' => $this->seg(),
|
|
]);
|
|
}
|
|
|
|
public function edit($id)
|
|
{
|
|
$p = (new Page())->find($id);
|
|
if (!$p) { $this->redirect('admin/pages'); }
|
|
$layout = [];
|
|
if (!empty($p['layout'])) {
|
|
$dec = json_decode($p['layout'], true);
|
|
if (is_array($dec)) $layout = $dec;
|
|
}
|
|
return $this->view('admin/page_builder', ['p' => $p, 'layout' => $layout]);
|
|
}
|
|
|
|
public function update($id)
|
|
{
|
|
if (!csrf_check()) { $this->redirect('admin/pages'); }
|
|
$layout = $this->post('layout', '');
|
|
// 校验:非空的 layout 必须是合法 JSON 数组
|
|
if ($layout !== '') {
|
|
$dec = json_decode($layout, true);
|
|
if (!is_array($dec)) $layout = '';
|
|
}
|
|
(new Page())->update($id, [
|
|
'title' => $this->post('title'),
|
|
'layout' => $layout,
|
|
'updated_at' => date('Y-m-d'),
|
|
]);
|
|
$this->redirect('admin/pages');
|
|
}
|
|
}
|