views:

346

answers:

3

I've got a very old php application (1999) that has been worked on during the last ten years. At this point the app starts to show it's age so i'm in te progress of migrating to a "new" framework, symfony 1.4. But since the app is very large, i cannot do this at once. So i'm planning to wrap the old app into the new symfony app, and convert functionality by functionality.

First step in this transition was making the old app appear in the new symfony app. So, i've created the "frontend" application, added a "legacy" module, made it the default homepage, and i've put everyhting i had in my index.php (all pages went through this index.php) in the indexSuccess.php file for the indexAction. I've added the code in the "view" because there are also functions in it and changing that setup would take me more time than i want to spend on the old app.

Unfortunately i've now got an issue with global variables. Let me give you an example (i would have never made this register function like this, but it is, so please look past that.

$session = new ps_session;
$demo = "this is a demo variable";
$session->register('demo');

In ps_session i have this method

public function register($var) {
    global $$var;
    $_SESSION [$var] = $$var;
}

So it should put the content of $demo in a session var named "demo". Clever right :) Anyway, var_dumping shows me the that $$var is "null" and $demo is filled if i var_dump before and after calling the function. Exact same code without symfony and it returns the correct content.

What am i missing? The global call is spread out in all area's of this massive app so i really don't want to switch to something else, so i'm hoping for a quick fix :)

Maybe relevant, the all code except the index.php content are in frontend/lib/legacy/ folder, the index is in frontend/modules/legacy/ (if there is some scope issue i'm missing)

A: 

I think that since your indexSuccess.php file is included inside a function (more precisely, here : lib/vendor/symfony/lib/view/sfPHPView.class.php:185 ), this can't work, because $demo is no longer in the global scope. I don't see any easy workaround for this... I think you should create a legacy folder in /web , and use routing to redirect to it if the url corresponds to something not migrated yet.

greg0ire
The problem with this (adding a $this->redirect('/legacy/index.php')) in the index action is that post variables (get vars i can fix) are not transmitted to the old index. I don't seem to find another solution in the docs about routing to see how i can handle this?
Roderik
Perhaps you could do something similar at the apache level, with rewriteRules or sth like that? in this case, POST information would not be lost I think
greg0ire
A: 

I went with putting the entire old site under web/legacy and redirecting from the default index action to the legacy folder. Most of the url's were made by mod_rewrite so easily fixed. The other url's went through a function so fixing was ok, and only a few were hardcoded. To make it totally transparant, i only need to redo the homepage to start from, so i don't have a visible /legacy/ in my url. Thanks for the help!

Roderik
A: 

I agree with greg0ire that this is an issue with the way sfPHPView includes indexSuccess.

Could you simply require index.php in the default/index action?

jeremy