Skip to content
Snippets Groups Projects
PageController.php 1.38 KiB
Newer Older
  • Learn to ignore specific revisions
  • /**
     * @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
    
            if ($params === []) {
    
                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
    
            $locale = service('request')
                ->getLocale();
            $cacheName = "page-{$this->page->slug}-{$locale}";
    
            if (! ($found = cache($cacheName))) {
    
                    'metatags' => get_page_metatags($this->page),
    
    
                // The page cache is set to a decade so it is deleted manually upon page update
    
                cache()
                    ->save($cacheName, $found, DECADE);