Integrate Zend Framework With Legacy Application - php

Is it possible to integrate Zend Framework with already existing legacy web application? The application is written horribly using so called spaghetti code (no separation between presentation and application logic, PHP, HTML and SQL are all together). It is a very large application with hundreds of pages and forms.
Does it make sense to introduce a framework now or should we just continue with the spaghetti code? It is not realistic to rewrite the whole application using a framework because it would be too difficult. Moreover, we need to add some new functionality to the application and we have a deadline. Should we use a framework for all the new parts of the website that we need to add or should we just go with the way it has been programmed by developers that worked on it before us?

This excellent post by Chris Abernethy shows how to route all requests through ZF and have the legacy scripts handled by a LegacyController. New pages and content that you create can use the standard ZF MVC. And you can slowly migrate the legacy scripts into standard ZF MVC.

I think you really could and should code the new bits of your application using a framework, and migrate the legacy bits to it whenever they bug. Refactoring is not difficult and can be done over a long period of time, and that could be a task when you feel bored.
I advise you to read this very interesting article about refactoring : http://www.joelonsoftware.com/articles/fog0000000348.html , by Joël Spolsky

yeah zf is a component framework so you can start buy creating new features using these new components or when you fix a bug to see if redoing it in zf will be faster.
I'm in a similar situation and what i started doing was creating a new site entirely and would embed these new features in certain pages within the old site (thru frames). This allowed me to code entirely in zf and replace the entire site piece by piece.

Related

How would I use the Joomla Framework vs. creating Joomla extensions?

I have experience with Joomla and have modified and wrote some simple Joomla extensions. I don't have experience using one of the popular PHP frameworks (such as CakePHP), but I was thinking about using the Joomla framework because I'm familiar with Joomla. How would I use the Joomla framework for a software project instead of using regular Joomla and writing the extensions needed for it to extend it's capabilities? Thanks!
The basic idea is that you:
Get a copy of either the whole framework or just the packages you need+dependencies (from github or composer) or use the older copy that is shipped with the CMS,
Bootstrap your application (JApplicationWeb or JApplicationCli).
Write your code using the MVC structure provided.
The big difference with writing a totally independent application is that you are doing just that, you need to build everything in the application whereas in the CMS there are already a lot of things in place. (The good part of that is that you can make new code with no legacy concerns.) For example, if you look at the JIssues project you'll see that they had to think about things like authentication. So as you would expect writing a simple application is simple, writing a complex one is complex.
You can see many examples of framework applications around, ranging from the ones found in the CLI folder of your CMS installation to JIssues, and of course the three web applications in the CMS are all examples of applications on the framework.
The Joomla Framework is intended (among other things) to be the platform upon which you can build a web-application. The framework is like the frame of one of those motorcycles they build on "American Choppers." It provides the backdrop so that you can hit the ground thinking about your app without worrying about User Authentication, database connection, and a thousand other things like those that get in the way of bringing your app to its potential audience.
If you're trying to extend Joomla, the current edition is what you should be using.

What is a good PHP framework for migrating an existing app to?

I've recently come on board with a PHP application. There has not been much design put into the app - there is a front controller, however, view, model and controller code is usually mixed together.
I would like to slowly start refactoring the code beginning with moving all the SQL queries into appropriate models. Having looked at a few frameworks, it seems that most frameworks are setup with the assumption that an app will be developed from scratch using that framework.
Is there a good framework that I can just kind of plug-in so that I can use the model libraries and then perhaps later on, integrate more of the app into the framework? Would Doctrine be a good tool for something like this? Or should I just setup my own models without relying on third-party libraries?
If you have an existing php application, then there is no point to migrate it to some framework. Frameworks help you to develop project faster - you already have one. At this point adding framework on top of what you have will only make your application more complex and, most likely, slower.
Instead of trying to find some magical framework, you should invest in refactoring (apply some OOP principles, like SOLID) and documenting the existing code. Maybe start incrementally add some unit-tests.
P.S. Doctrine is an ORM ( 1.x implements activerectord , 2.x - something like a datamapper ). ORMs are for people who are extremely lazy, misguided or do not understand SQL. By moving your existing SQL queries to ORMs code you will make it all only slower. Additionally, you will encounter problems when migrating complicated queries. Just dont do it.
I've just started rewriting a site in Kohana, and I'm quite happy with it. It seems flexible and powerful. It's very similar to CodeIgniter, but a little more modern (more of the latest PHP features are used).
If you want only MVC (not HMVC or more difficult) frameworks for simple adoptation with existing application you should touch CodeIgniter. ActiveRecords is very easy for refactoring from existing sql-queries. You even can use default or hand made functions or classes for building queries in its models.
But default, Codeigniter isn't enough flexible for difficult or multi-namespacing applications.
Im migrating a site using Zend and Doctrine2.
The site wasn't OOP in any sense but it was divided between logic view and dal. The migration is still in process (new features are coded with framework, existing feature gets migrated only when big changes are needed).
Both frameworks are non intrusive, and the most valuable thing you get for me is to standarize things.

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

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($_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.

Object oriented php CMS or framework

I'm embarking on a very big exercise to build a CMS in php. It's actually my attempt to learn PHP in a fun (and hardcore) way coming from a Java background. Java is all object oriented so oop is in my blood, but I'm finding that OOP hasn't made it yet to PHP. Most PHP is still being written today the old way without the new concepts.
I'm trying to find an example PHP CMS that's written as object oriented. I hear Xoops is. Any others you know of? or any OOP libraries in general that you know of that could help me in a CMS project.
I would suggest symfony framework as it is well documented and functional framework that helped building many web applications.
http://www.symfony-project.org/
PHP5 is pretty OOP. Look for CMSes and frameworks that only work on PHP5. For example, Kohana
Concrete5 is a pretty complex OOP based CMS. Might be a harsh start but I've learned a lot by working with it.
again, +1 for symfony, but this is a large project and getting to know symfony will consume most of your time, yet if you want to dive in, its documentation is really great.
since you are trying to build your own CMS, get started with easy to grasp frameworks and build upon them. Don't waste your time on everything that has been already done. I recommend you Codeigniter MVC Framework http://codeigniter.com and for CMS, PyroCMS http://pyrocms.com which is built upon codeigniter is cool. Codeigniter is really easy to get along, and documentation is very neat and clean.
Further, if you like to start with a simple php framework, here's what Tyrehall has done, http://github.com/tylerhall/simple-php-framework . This project can act as a base for your CMS
No one seems to have mentioned Kohana the PHP 5 only framework.
Kohana has a pretty active and very helpful community to back it up (#kohana on freenode in particular).
edit: Upon closer inspection I see someone has already mentioned Kohana.
what you will notice is that what is more important to most cms (and framework) developers is MVC pattern implementation. Most MVC implementations in php do in fact use oop practices (some stricter than others)
+1 for symfony, and another I'd like to recommend is Kohana (built on CodeIgniter)
Also have a look at their forums, as both already have a cms or 10 built using these frameworks.
Using these frameworks brings you about 60% there, as a lot of the rudimentary tasks are taken care of.
edit
also remebered this one: fatfree framework it's quite lightweight: http://fatfree.sourceforge.net/
Have a look at Phundament 3.
Phundament 3 is an application foundation built upon a set if independent Yii modules and extensions such as user, rights, yiiext, gtc, ckeditor, jquery-file-upload, p3widgets and p3media.
The combination of p3widgets and p3media provides basic content management system (CMS) features, like dynamic widget creation and file management.
Combined in ckeditor, p3media acts as a ckfinder plugin which gives you the full power of HTML and media files for content creation via p3widgets.
It comes with a very minimalistic setup which integrates perfectly into an Yii web application skeletion and installs with one single command.
as some folks suggested here, you should start with Codeigniter because it's really easy to dive in. Its documentation is very well structured and easy to read. But I think Codeigniter seems to be very old now.
What I really recommend to you is Laravel. There's another Framework you should look into, that's FuelPHP. But for me, Laravel has absolutely changed to way I'm writing my PHP code. It is the best framework I've ever seen in my life. It's so elegant that you will instantly fall in love with.
If Laravel suits you, I recommend you to follow this online course by Jeffrey Way # Tutsplus.com. You will love it!
Good luck :)
Have you seen CakePHP?
http://cakephp.org/
Its a MVC framework for PHP. Its pretty robust and can be used in a fully object oriented manner.

Website Development Problem CakePHP, WordPress or Start From Scratch?

I'm in the process of starting a new web site that is something like stackoverflow but a little bit more different along with making the members profiles highly more customizable I was thinking of building it from scratch using PHP, but was thinking of using CakePHP, but then I thought WordPress sounded better but I remember working with wordpress and it was a little bit slow at times when you tried to browse the web site.
So what I guess I'm trying to ask is that should I design the site from scratch? And I heard techcrunch.com and 9rules.com are completely done in WordPress, is this true?
Wordpress is a blogging engine, which is a specialised kind of CMS. It's not suitable for building something like Stack Overflow on.
CakePHP on the other hand is a framework - something to help you build a website so you're not starting from scratch. This would be a good bet.
For other PHP frameworks check these questions:
What PHP framework would you choose for a new application and why?
PHP Framework Decision - Analysis paralysis!
Be sure to check other frameworks too. CakePHP is a framework which makes a lot of choices for you. If your application fits in it probably works like a charm, but otherwise a framework can be a huge pain. Zend Framework has a lot more flexibility, but it also takes a lot more time to bootstrap your project. In the end it is all about personal preferences, so I would recommend you to just try some frameworks and find out how it feels for you.
Some frameworks:
Zend Framework
Symfony
CodeIgniter or it's successor Kohana
Wordpress isn't slow, if get decent web hosting and know how to tune a webserver. But no, it won't really suffice for this. FastCGI on a threaded webserver with enough memory to cover peak traffic is the way to go.
Drupal (and maybe Plone) could probably do what you want without coding, but you'd still have to learn a lot, so you might not gain much over just coding the thing.
Using wordpress or joomla or any other framework will require enormous emounts of custimization of the framework to meet your ends. If you are not very comfortable with using those frameworks and how they are built, you are probably better off writing by hand, and maybe develop your own framework that suits your own needs.
Hand code the novel aspects of your site first without concern for the final product. You goal should be to find what you really need and how you are going to need them. For instance, if you need a blog for the staff, then you can install WordPress and move on to the next problem (your branding can be duplicated to a WordPress theme).
If existing software solves the problem, then version 1.0 should be a Frankenstein solution (which sucks aesthetically). The idea is to map out the incongruities between the various problems you are trying to solve so that when you do rewrite everything you do not produce the same problems.
Ideally, you will spend most of your time adding value to what you need that is novel about the site.

Categories