2

My team of coworkers and me have decided to rewrite a legacy app in Yii but the management have a strict policy that all the functionality must remain as it is, so we have to use old modules until they are ported to Yii, these modules are written in a procedural manner and every one of them has a php file that is included in the general index.php. The general index.php does three things:

  • Starts the session and adds variables to it.
  • Creates the db connection.
  • Renders the main php file of the requested module.

How can we use the old modules once we begin to use Yii?

We have looked at URL Management and the logic would be really simple: If the url matches an old module, render it with renderFile() else let do Yii the work, however we don't know if this is the best approach.

Should we consider anything else before beginning the process?

I want to know if URLManagement + renderFile() is the way to go?

Afnan Bashir
  • 7,319
  • 20
  • 76
  • 138
Mario Marín
  • 131
  • 1
  • 8
  • 2
    If you have a legacy codebase , slapping on a framework wont make it better. Hell .. it will just add another layer of crud. Instead you should start slowly refactoring it. – tereško May 12 '12 at 08:04

2 Answers2

1

The URL handling can indeed be used, but then I would simply write a custom URL Rule class instead of using a ton of routes as your config will be a mess.

If you want some alternative suggestions:

To begin with, split out the creation of the app and its execution

require_once($yii);
Yii::createWebApplication($config);

// If you want to run the app:
Yii::app()->run();

That way you are in full control whether the app actually runs or not.

As for the DB. If you are using PDO you are in luck. I would just give Yii a db component the regular way and then modify the general.php to use the PDO instance from Yii (Yii::app()->db->pdoInstance). It will always be loaded after so that should work. If you aren't using PDO, just use 2 connections, it's not that bad unless you have a lot of visitors.

Regarding the session there shouldn't be that much initialization so unless you have a custom handler, move it to Yii as well. The functions are the same anyway so there shouldn't be much of a problem.

Then there are 2 ways of doing things as I see it:

1) general.php goes first.

You would have to make a list of modules in the legacy file and determine if the current requested module was migrated or not. Basically put the module names that are still in general.php in an array, see if the url requires one of those and include general.php (and don't do Yii::app()->run()). The rest go through Yii.

2) Yii goes first.

Have yii do it's magic but intercept the 404 http exceptions. This is easily done with a custom error handler function (http://www.yiiframework.com/doc/guide/1.1/en/topics.error). If you get to the error function again: determine if its a valid legacy module and include general.php.

Both ways are pretty messy but at least like this you get the chance to migrate one module whilst keeping the rest in the legacy file.

Blizz
  • 8,082
  • 2
  • 33
  • 53
0

Depending on Size ,complexity and Person Months for a software is critical to take any decisions. Of course it is very very advisable to have homogeneous nature of application rather than heterogeneous nature. If modules you mentioned above are the one you intend to convert I suggest you must have a RE-DO in Yii because Yii has strong ORM modules are very very easy to make.

I suggest you should go for a RE-Do

Following may be of your interest How do you convert an old OOP PHP project into the Yii Framework?

Community
  • 1
  • 1
Afnan Bashir
  • 7,319
  • 20
  • 76
  • 138
  • We plan to rewrite the entire application but we must preserve every module until it gets replaced by the modules written with Yii, therefore we can't afford an homogeneous nature in our application yet. – Mario Marín May 10 '12 at 19:28
  • Thank you Afnan, the link is really useful but I want to know if URLManagement + renderFile() is the way to go. – Mario Marín May 11 '12 at 14:16