Symfony2 + WordPress

I once asked about the possibility to integrate a symfony2 app into a wordpress page. And I did get a nice response here. I quoted the response here below as well:

What I would suggest is checking to see if you have a route match in your Symfony2 front controller (ex: app.php) and if there is no match, bootstrap and forward to drupal[wordpress].

You’ll want to add a symlink in the/web directory to drupal[wordpress], in order to get this to work. You can then modify your request object to use this directory as it’s web directory, and all routes will be passed through transparently. Stick the code below in drupal’s[wordpress’] front controller:

class DrupalRoutedRequest extends \Symfony\Component\HttpFoundation\Request 
{
    public function getBasePath()
    {
        if (null === $this->basePath) {
            // add your symlink
            $this->basePath = $this->prepareBasePath() . '/drupal';
        }
 
        return $this->basePath;
    }
}
// in app.php
$kernel = new AppKernel('dev', false);
$kernel->loadClassCache();
 
$response = $kernel->handle(\DrupalRoutedRequest::createFromGlobals());
 
if ($response->getStatusCode() != 404) {
    $response->send();
    return;
}
// do drupal bootstrapping / regular front-controller goodness

I hope this helps!

One thought on “Symfony2 + WordPress

  1. Hello,

    I’m sorry but i don’t understand. I understand the concept (i think) but abolutely not the implementation… Have you tested it?

    Tks

Leave a Reply

Your email address will not be published. Required fields are marked *