Skip to content

Instantly share code, notes, and snippets.

@mrunkel
Last active August 16, 2021 13:23
Show Gist options
  • Save mrunkel/69bfddaf397133cad02066bfa527b85b to your computer and use it in GitHub Desktop.
Save mrunkel/69bfddaf397133cad02066bfa527b85b to your computer and use it in GitHub Desktop.
Symfony controller to add kirby to a symfony project
<?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;
}
}
# 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