Last active
August 16, 2021 13:23
-
-
Save mrunkel/69bfddaf397133cad02066bfa527b85b to your computer and use it in GitHub Desktop.
Symfony controller to add kirby to a symfony project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Controller; | |
use Kirby\Cms\App as Kirby; | |
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | |
use Symfony\Component\HttpFoundation\Response; | |
class KirbyController extends AbstractController | |
{ | |
public function index(): Response | |
{ | |
$base = $this->getParameter('kernel.project_dir'); | |
$webroot = $base . '/public'; | |
$site = $base . '/site'; | |
$storage = $base . '/var/storage'; | |
include $base . '/vendor/autoload.php'; | |
$roots = [ | |
'roots' => [ | |
'index' => $webroot, | |
'base' => $base, | |
'content' => $base . '/content', | |
'site' => $site, | |
'blueprints' => $site . '/blueprints', | |
'config' => $site . '/config', | |
'controllers' => $site . '/controllers', | |
'plugins' => $site . '/plugins', | |
'snippets' => $site . '/snippets', | |
'templates' => $site . '/templates', | |
'storage' => $storage, | |
'accounts' => $storage . '/accounts', | |
'cache' => $storage . '/cache', | |
'sessions' => $storage . '/sessions', | |
], | |
]; | |
// trick the panel into working | |
$_SERVER['SERVER_SOFTWARE'] = 'nginx'; | |
$kirby = new Kirby($roots); | |
$response = new Response($kirby->render()); | |
return $response; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in config/ | |
#index: | |
# path: / | |
# controller: App\Controller\DefaultController::index | |
kirby_pages: | |
path: /{match} | |
defaults: { _controller: App\Controller\KirbyController::index } | |
requirements: | |
match: .* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment