Skip to content
Snippets Groups Projects
PageController.php 2.79 KiB
Newer Older
  • Learn to ignore specific revisions
  • <?php
    
    /**
     * @copyright  2020 Podlibre
     * @license    https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
     * @link       https://castopod.org/
     */
    
    namespace App\Controllers\Admin;
    
    
    use CodeIgniter\Exceptions\PageNotFoundException;
    use CodeIgniter\HTTP\RedirectResponse;
    
    class PageController extends BaseController
    
        public function _remap(string $method, string ...$params): mixed
    
            if ($this->page = (new PageModel())->find($params[0])) {
    
        {
            $data = [
                'pages' => (new PageModel())->findAll(),
            ];
    
            return view('admin/page/list', $data);
        }
    
    
            return view('admin/page/view', [
                'page' => $this->page,
            ]);
    
        public function attemptCreate(): RedirectResponse
    
                'title' => $this->request->getPost('title'),
                'slug' => $this->request->getPost('slug'),
    
                'content_markdown' => $this->request->getPost('content'),
    
                return redirect()
                    ->back()
                    ->withInput()
                    ->with('errors', $pageModel->errors());
            }
    
            return redirect()
                ->route('page-list')
    
                ->with('message', lang('Page.messages.createSuccess', [
                    'pageTitle' => $page->title,
                ]),);
    
            replace_breadcrumb_params([
                0 => $this->page->title,
            ]);
            return view('admin/page/edit', [
                'page' => $this->page,
            ]);
    
        public function attemptEdit(): RedirectResponse
    
        {
            $this->page->title = $this->request->getPost('title');
            $this->page->slug = $this->request->getPost('slug');
    
            $this->page->content_markdown = $this->request->getPost('content');
    
            if (! $pageModel->update($this->page->id, $this->page)) {
    
                return redirect()
                    ->back()
                    ->withInput()
                    ->with('errors', $pageModel->errors());
            }
    
            return redirect()->route('page-list');
        }
    
    
        public function delete(): RedirectResponse
    
        {
            (new PageModel())->delete($this->page->id);
    
            return redirect()->route('page-list');
        }
    }