开发者

Is it a good idea to work a php framework into an existing php app without one?

开发者 https://www.devze.com 2023-01-26 17:02 出处:网络
I\'m working on a large php site that currently does not use any framework.My big question would be, is it advisable to slowly try to work a framework into the application over time, such as in new pa

I'm working on a large php site that currently does not use any framework. My big question would be, is it advisable to slowly try to work a framework into the application over time, such as in new parts that are created and older parts as they are updated?

For example, all pages are served directly by url, and dozens of them look like this

//monitoring_projet.php
<?php
session_start();
require_once($_SERVER['DOCUMENT_ROOT'].'/include/header.php');
require_once($_开发者_Python百科SERVER['DOCUMENT_ROOT'].'/include/config_ats.php');
$page_link = 'monitoring_projet.php';
?>

<div id="content" style="padding-left:10px;margin:0 10px">
<br />
<?php
include($_SERVER['DOCUMENT_ROOT'].'/include/gestion_projet_entreprise.php')
?>
</div>

<?php require_once($_SERVER['DOCUMENT_ROOT'].'/include/footer.php'); ?>

I've been reading up on Zend Framework as my php framework poison of choice. Would it be a good idea to try and use ZF just to bootstrap the app and get all this common code into one place? Or is adding a framework into the mix going to cause more headaches than its worth at this point?


IMHO, plugging in a framework into a project like that just spells trouble; I imagine that configuration, dependency management and such would be a real hassle.

The approach I think would work best here is to make a separate blank framework project, define the views, controllers and models according to your project specs, then plug in the code from your current pages, distributing code among controllers and view appropriately. That way, you can migrate configuration and support classes into the framework without trying to bend the framework to suit your project.


It completely depends on your skills and on the system you're trying to convert to Zend.

At the job I'm working right now, we are slowly adding Zend Framework libraries in it, which is going pretty well.

If you want to replace your complete website with Zend Framework (ajusting to the MVC pattern) over time, it is a different story. In that case you get all kinds of trouble. You are suddenly forced to use a certain design pattern your current code is unable to deal with. At that point you will get headaches cause you will soon lose the overview of what you're doing. Don't do that slowly, but do it in one step. It could give you headaches too, but only for a short time.

Good luck!


I currently work for a company that is introducing Zend Framework to its current code base. It has caused problems but is now slowly getting better. As Krof DraKula mentions, dependency management can be a problem and configuration caused some headaches.

We had a DAO, BO, VO pattern that worked well but was getting messy to work with. We are slowly migrating classes over to ZF stylee. If you are serious about doing this I would recommend going slowly, get the two styles running side by side. At first we ran Zend Framework modules alongside our legacy stuff and only when that was working flawlessly did we start migrating and refactoring.

If you have the skill and the time to migrate you won't regret it, I'm sure.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号