0
votes

I've got a pretty big Symfony 1.2 project to migrate.

First, I modified my .htaccess so I can have some pages handled by Symfony 2.

What I'd like to do, to make the migration smoother, is to be able to render some SF2 action/templates/methods/... inside SF1.

I added the autoloader to the SF1 app, so I can access to twig rendering methods and other stuff.

But how can I call a SF2 action ?

For example, if I want to migrate only the footer first, I would also need some php methods, not only rendering. That was previously in SF1 component, where should it be now ?

If you've got any suggestion about the way of migrating, don't hesitate !

EDIT 1 :

Apparently, the only way to do something like that is to render a full twig template, and/or in this template call some other partial twig templates with render(url, params).

Here is my SF1 code to be able to render twig templates :

public static function getTwig()
{

    require_once __DIR__.'SF2_PATH/vendor/twig/extensions/lib/Twig/Extensions/Autoloader.php';
    Twig_Autoloader::register();
    $loader = new Twig_Loader_Filesystem( __DIR__.'SF2_PATH/sf2/src/VENDOR/BUNDLE/');
    $twig = new Twig_Environment($loader, array(
        'cache' => __DIR__.'SF2_PATH/sf2/app/cache/dev/twig',
    ));
    return $twig;
}

And so :

$twig->loadTemplate('header.html.twig');

EDIT 2 :

That doesn't seem to work, if in a twig template I try to render an other one with {{render(controller('BUNDLE:CONTROLER:ACTION', {})) }} for example Twig_Error : The function "controller" does not exist. And if I try to render the url Unknown tag name "render".

I guess Symfony 2 twig functionalities are not loaded, how can I do that ?

EDIT 3 :

Ok, now I can do it, but I've got the following message...

Twig_Error_Runtime An exception has been thrown during the rendering of a template ("Rendering a fragment can only be done when handling a master Request.") in ...

1
For moving from symfony 1 to 2 a complete code rewrite is neccesary, as many thinks changed.Emii Khaos
I know, I'd just like to be able to render some SF2 templates in SF1 so the migration will be easier. // EDIT : To make it short, I'm trying to bootstrap SF2 in SF1, so I can rewrite my full modules one by one (.htacess dispatching) and render some in SF1 (rendering a SF2 menu in SF1 for example).Bonswouar

1 Answers

0
votes

EDIT : I solved it !

Here is my full bootstrap method to render a Twig template and be able to use some Symfony 2 functionalities, in Symfony 1.

    $loader = require_once __DIR__.'/../../../sf2/app/bootstrap.php.cache';
    Debug::enable();
    require_once __DIR__.'/../../../sf2/app/AppKernel.php';

    $kernel = new AppKernel('dev', true);
    $kernel->loadClassCache();
    Request::enableHttpMethodParameterOverride();
    $request = Request::createFromGlobals();
    $kernel->boot();
    $kernel->getContainer()->enterScope('request');
    $kernel->getContainer()->set('request', new \Symfony\Component\HttpFoundation\Request(), 'request');
    $this->container = $kernel->getContainer()->get('twig');