Converting a Brownfield PHP Webapp to Zend Framework - zend-framework

We're thinking of converting our PHP Webapp from using no framework (which is killing us) to use Zend Framework. Because of the size of the application I don't think starting from scratch is going to be a viable option for management so I wanted to start researching how to slowly convert from the current site structure to one using Zend Framework but there isn't a lot of information on this process.
So far my plan is to dump the current code base into the public/ directory of the Zend Application, fix the numerous problems that I'm sure this will crop up and then start rewriting modules one at a time.
Has anyone had experience doing this in the past and how did it work out for you?

I've done a few of these now. What worked best for me was putting ZF 'around' the old app, so all requests go through ZF. I then have a 'Legacy' controller plugin, which checks whether the request can be satisfied by ZF, and if not, sends it to the old app:
class Yourapp_Plugin_Legacy extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$dispatcher = Zend_Controller_Front::getInstance()->getDispatcher();
if (!$dispatcher->isDispatchable($request)) {
// send to the old code...
}
}
}
exactly how you then send the request to your old app depends a bit on how it is implemented. In one project, I examined the request, determined what file from the old code the request would have gone to, and then required that in. It sounds like this might be appropriate for you. In another project my solution was to route all these requests to a LegacyController in the ZF project, which ran the old code to get the resulting HTML and then rendered it inside the Zend_Layout from the new project.
The advantages of this approach are that you can gradually introduce ZF modules as you rewrite parts of the old app, until you reach the point where 100% of requests can be served by ZF. Also, since the ZF project has initialized before your old code is run, your old code can use the ZF autoloader, so you can start replacing classes in the old code with models written in a more ZF-style, and have them used by both parts of the app.

Related

ZF2 Album tutorial using stored procedures

Please also suggest which namespace to use. I am new to zend and MVC.
module.php
public function getServiceConfig()
{
// what code here?
}
**Album\Model\Album.php**
{
//what code here?
}
**Album\Model\AlbumTable.php**
{
//what code here?
//do we have to use this class or a different class?
}
I can understand the sudden confusion when starting out with ZF2. However, the manual has really done a good job at helping those who are just starting out. You can find the most up-to-date information here : http://zf2.readthedocs.org/en/latest/user-guide/overview.html
Once you've got the Skeleton Application working I believe some of your confusion will be relieved. If not, come back and ask more specific questions OR you could even join the FreeNode IRC channel at #zftalk.
But to also help answer some of what you've asked here:
getServiceConfig() is where you will interact with the ServiceManager. Try to stay away from closures and work with Factories.
Album.php is sort of like the Hydrator. You don't have to use a Hydrator but for example purposes it was put here. It can make like easier in the long run.
AlbumTable.php is the Database Table you will be interacting with.
The namespace which is used in the tutorial is called Album. The Skeleton application comes packaged with a namespace called Application to start with.
You can manually download ZF2 here: https://packages.zendframework.com/
The latest skeleton application can be found here: https://github.com/zendframework/ZendSkeletonApplication
You may also choose to use Composer to install your entire application which tends to make the installation process much easier for those just starting out, so in your situation I'm going to recommend you use that. You can find instructions on how to use Composer here: http://zf2.readthedocs.org/en/latest/user-guide/skeleton-application.html

LoadRunner and wicket application

Doing some research with regards to application framework used on the SUT am going to LoadTest using Loadrunner I fond the application is developed using wickets.
I have generated script using web http/html protocol against a wicket
application and there was some calls recorded in the following
format,script is failing at this URL when i ran the script in VUGen.
http://somem/nnnweb/main/ ?
wicket:interface= :1:someSearchForm :someSearchForm :searchInfo: :IActi
vePageBehaviorListener :0:&wicket: ignoreIfNotActiv e=true&random=
0.038901654740178815",
I find out like when i generate the script which has just views(
viewing tabs) is working fine, but when i edit somefileds and submit
the script is generating the above calls ( http://xxx...) and failing
This guy has explained just the same issue here:
http://tech.groups.yahoo.com/group/LoadRunner/message/27295
I hope it is ok to refer other sites in Stackoverflow?
General question. Does loadrunner support testing of wicket application and is TruClient the best choice here? I actually got it to work with TruClient, but as I understand there are drawbacks with memory footprint using TruClient, but maybe it is time to move on to next generation protocol given my project has decided to use wicket framework?

Zend/Controller/Action.php file missing

I'm new to Zend framework, and was trying out the Guestbook tutorial that Zend has on it's web site. I have the latest framework downloaded and setup properly; php.ini include_files has the library location set correctly. In the Guestbook tutorial, the GuestbookController extends Zend_Controller_Action and that's what I typed, but I keep getting error stating that Zend_Controller_Action is not found. Turns out, the folder Controller is missing from /library/Zend. I tried re-downloading Zend Framework thinking I might have accidentally deleted it, but it's not in the newly downloaded framework directory either. So, where can I get the Controller folder that contains all the required class files? Or how can I fix the issue? Any help is much appreciated.
Thanks
Kuni
It sounds like the tutorial you are following is for ZF1. ZF2 was released last year and works quite differently. You might want to try the quickstart from the current manual instead:
http://framework.zend.com/manual/2.0/en/user-guide/overview.html
Alternatively you can still download version 1.12 from the Zend site.

How do I make a separate View path/directory for iPhone in Rails?

I'm making an iPhone version of an existing Rails app. I'd like to make the mobile version accessible via a subdomain such as iphone.mysite.com.
I know I can use formats and the respond_to block for individual erb files, such as index.iphone.erb as show here:
Creating an iPhone optimised version of your Rails site using iUI and Rails 2
But I'd like to keep entirely separate view directories for the mobile version and regular version such as this:
app/views/iphone
Here's what I've tried in my Application controller:
class ApplicationController < ActionController::Base
before_filter :set_site
def set_site
subdomain=self.request.subdomains[0]
ActionController::Base.prepend_view_path("app/views/#{subdomain}")
end
When testing this, however, the view switches to the view associated with the last requested subdomain by any user.
For example, if I visit http://iphone.mysite.com, then immediately go to http://www.mysite.com in another separate browser, I see the mobile version instead of the regular one. Refreshing it will correct this and bring up the right version. But if I go back to http://iphone.mysite.com in the other browser and refresh, it brings up the non-mobile site! I'm tearing my hair out and not understanding what's going on.
Any advice would be much appreciated.
Edit 1
Vlad below found a link with a possible solution however it is not working for me. Here is the code I tried. I made a file called subdomain_view.rb and placed it in config/initializers:
# Put all of this in a bootstrap-only initializer
ActionController::Base.class_eval do
APP_ONE_VIEW_PATH = "app/views/iphone"
APP_TWO_VIEW_PATH = "app/views/default"
cattr_accessor :application_view_path
self.view_paths = ["app/views", APP_ONE_VIEW_PATH, APP_TWO_VIEW_PATH]
# This is where you determine the switching mechanism for your application. Here, it is a simple GET parameter.
# You can probably argue that this specific piece SHOULD be in your actual app_controller class definition, as it is the only piece
# of info pertinent to the rest of your application.
before_filter do |controller|
ActionController::Base.application_view_path = request.subdomains[0]=="iphone" ? APP_TWO_VIEW_PATH : APP_ONE_VIEW_PATH
end
end
require 'aquarium'
ActionView::PathSet.class_eval do
include Aquarium::DSL
before :find_template do |join_point, object, *args|
object.each_with_index do |path,i|
object.unshift(object.delete_at(i)) if path.to_s == ActionController::Base.application_view_path
end
end
end
# I'll leave the exercise of testing this or implementing it for your particular app up to you.
With the above code, I am getting the same view no matter what subdomain I put in. Any suggestions on what might be wrong? Am I putting this code in the wrong place?
First, you have an error in your approach. You only 'set' a view path, you don't 'unset' it. When you do something like
ActionController::Base.prepend_view_path
this actually persists between your requests (internally, you are setting a class variable, and because classes are cached in production, this variable remains set between requests). Therefore, the current view path is the view path of your last request.
IMO, you should dynamically compute view_path for your current subdomain (this implies some ActionView hacking). A nice solution is provided here.
I was able to solve the problem by using a gem called themes_for_rails:
https://github.com/lucasefe/themes_for_rails
After installing the gem, here's what I added to my application files:
#application_controller.rb
class ApplicationController < ActionController::Base
theme :theme_resolver
def theme_resolver
current_subdomain=self.request.subdomains[0]
end
end
#routes.rb
MyAppName::Application.routes.draw do
themes_for_rails
end
#Gemfile
gem 'themes_for_rails'
I placed my themes in [application_root]/themes. Make sure you don't put it in [application_root]/app/themes.

zend framework under document root in subdir

I developed a application with Zend Framework and now I want to be able to place the app in an subdirectory of a Documentroot.
e.g. http://www.example.com/myapp/
I read quite a lot of Docu how this could work, but all in all these solutions don´t fit my needs. Is there a trivial way to do the subdir thing, without adding the concrete path to any file which generates the pages.
There are some examples in the net, where a basePath is set in the application enviroment and so there is a method call bevor each "form" creation which prepends the path before the link.
$form->setAction($this->_request->getBaseUrl() . $this->_helper->url('sign'));
This was from: http://johnmee.com/2008/11/zend-framework-quickstart-tutorial-deploy-to-a-subdirectory-instead-of-web-root/
But this is only works for small examples, I have tons of forms, tons of views and tons of scripts. I can´t belive this (lets call it hack :) ) is the only solution to do this.
Any ideas?
You don't have to do anything special. See my tutorial at http://akrabat.com/Zend-framework-tutorial which is developed entirely within a sub-directory.
As they say on the web page:
I’m told this last issue has been
lodged has a defect and not necessary
from releases “1.7″ and beyond. The
helper->url will henceforth prepend
the baseUrl to its result.
So you should be fine. Do you actually use the $form->setAction() method on every form already? Because if you use it in combination with the url helper, the baseUrl will already be included.