Skip to content
Snippets Groups Projects
PageController.php 1.24 KiB
Newer Older
/**
 * @copyright  2020 Podlibre
 * @license    https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
 * @link       https://castopod.org/
 */

namespace App\Controllers;

use CodeIgniter\Exceptions\PageNotFoundException;
class PageController extends BaseController
    public function _remap(string $method, string ...$params): mixed
            throw PageNotFoundException::forPageNotFound();
            ($page = (new PageModel())->where('slug', $params[0])->first()) === null
            throw PageNotFoundException::forPageNotFound();
        $this->page = $page;

        return $this->{$method}();
    public function index(): string
        if (! ($found = cache($cacheName))) {
            $data = [
                'page' => $this->page,
            ];
            $found = view('page', $data);

            // The page cache is set to a decade so it is deleted manually upon page update
            cache()
                ->save($cacheName, $found, DECADE);