Framework for Web Services in PHP? - php

I need to implement a Web Service in PHP, but I've never written one in it (I nowadays use ASP.net which handles all that SOAP/WSDL/Disco stuff for me).
Are there any libraries/Frameworks for that? Should be as lightweight as possible as they wire into an existing system.

You might want to take a look at Zend Framework. It's an fully featured framework and it is basically just a bunch of loosely coupled components. You don't have to use anything you don't want to.
You can view the components here. Notice there is Zend_Soap and others.

Try NuSOAP it's lightweight and very easy to use.

PHP comes with a SOAP client built in:
http://us.php.net/soap
and there's always the ZF version:
Zend Framework: Zend_Soap

Related

Design Pattern/Workflow for a JavaScript / Ajax / PHP - Application

I'm creating a small Web-Application with PHP, JavaScript, Ajax and of course HTML and CSS (and a bit jQuery).
Is there a Design Pattern which you recommend?
I know MVC, but only in Java, C++.
I'm just starting with PHP and JavaScript, and search for a source which can tell me how to use these languages correctly (in form of how they should interact with each other)
My Idea is to use PHP only for DB connects and store all data "locally" in JavaScript vars, and work with them.
So, my questions:
Are there any Frameworks (should be very small, i want to code most
of the functions on my own)
Is there a book/website which can train me to do it the right way? (or do you have any links?)
There are lot of web application frameworks in PHP out of which few are really famous in development world.
cakephp http://cakephp.org/
codeigniter http://codeigniter.com/
Both of them has rich support for MVC pattern and almost similar to spring and struts in java world.
A valid answer should not refer to Zend Framework, Code Igniter or Cake PHP.
In my opinion Silex could be the framework you search. It is a microframework which uses some parts of Symfony2 but is very lightweight and very easy to learn.
From the docs:
Silex is a PHP microframework for PHP 5.3. It is built on the shoulders of Symfony2 and Pimple and also inspired by sinatra.
A microframework provides the guts for building simple single-file apps. Silex aims to be:
Concise: Silex exposes an intuitive and concise API that is fun to use.
Extensible: Silex has an extension system based around the Pimple micro service-container that makes it even easier to tie in third party libraries.
Testable: Silex uses Symfony2's HttpKernel which abstracts request and response. This makes it very easy to test apps and the framework itself. It also respects the HTTP specification and encourages its proper use.
And the simplest application would just require something like this (from the docs):
require_once __DIR__.'/../vendor/autoload.php';
$app = new Silex\Application();
$app->get('/hello/{name}', function($name) use($app) {
return 'Hello '.$app->escape($name);
});
$app->run();
This does everything a Controller does and even more. You then could add Twig to have a solid start for the View part. And for the Model part you could add Doctrine2 which has a great Object Relational Mapper (ORM) and even a Object Document Mapper (ODM) if you like NoSQL.
I recommend you to use Zend Framework. It's not "light" framework but is very modular and scalable. So you can use only few modules that you need and write rest of code by yourself. Another advantage is that is one of the most commonly used framework and have great documentation. Please see also javascript framework which can be useful for your project - http://knockoutjs.com/

Zend PHP Framework and Server process

is there any way I can use Zend only for server process?. I want to have all my client process in javascript and the server process in php using Zend framework or any other framework.
Any ideas are welcome.
Zend is a component library that let you do php on the server side - So yes! you can use it to handle all your clients' process.
BTW, it's a good practice to leverage ZendFramework MVC so you will start with great concept/project structure etc'.
Good luck!
The answer is: of course!
ZF is a server-side framework. It's completely agnostic about it's output format. You'll find you have no problem outputting json, or xml, or whatever format you like.
While it's typical to have your application output HTML pages via Zend_View/Zend_Layout, there are other components available to facilitate sending non-HTML output..
If you're doing a fancy javascript-driven client, you might consider going the RESTful route with Zend_Rest_Route, and/or Zend_Rest_Controller.
In your comment, you mention concern about Zend_Form. You're free to ignore Zend_Form -- though you might want to reconsider. It's quite possible to leverage the filtering/validation functionality of Zend_Form (define a form, and just use populate(), isValid(), etc) without ever rendering a form. I did a project not long ago that was a single-page app using ExtJS on the client side, which which talked to a set of RESTful services in JSON provided by ZF. I used Zend_Form extensively just for filtering/validating data.

ASP.NET MVC 2 is comparable to what PHP MVC?

I've been doing a lot with ASP.NET MVC 2 at work and I'd like to utilize my new skills at home... but I have Apache servers, not IIS.
What PHP MVC solutions are the same or at least comparable to ASP.NET MVC 2?
;-) Here's a list another developer has found: http://www.mustap.com/phpzone_post_73_top-10-php-mvc-frameworks.
The #1 solution he recommends is Symfony
Why not use mono? I believe you can directly use your asp.net mvc skills and deploy to your apache servers.
http://www.mono-project.com/Main_Page
There are a number of PHP MVCs to look at:
CakePHP
Expression Engine
Kohana
Zend Framework
Kohana is the only one I've done work with and I found it fairly easy to get started. It's open source and specifically created to support PHP 5.2+ so it has a clean, object-oriented codebase.

A CMS on 2 DIFFERENT frameworks?

I'm not sure if this is possible, but let's say you want to build a CMS, but you're torn between 2 frameworks because each has some features that you like. Is it possible to create the CMS with both framewoks? Does this approach have merits or pitfalls?
Speaking strictly about the Zend Framework (ZF) I would say yes. ZF components are written to be as independent from other components as possible. I would say that it would not be very difficult (It may actually be quite common) to integrate libraries of ZF into other frameworks like Cake, Symfony, or Codeigniter.
Is it possible to create the CMS with both framewoks?
While it's possible to use components from the Zend Framework inside other Frameworks / CMSs - this may be the case with other component libraries as well, but Zend's the most modular one that I know - It's usually not a good idea to mix two full-blown Frameworks.
Many central functions like MVC structures, URL routing, the database layer, Unit testing, error management and so on are by nature unable to be served by two frameworks at once without massive friction. Also, you're likely to get problems when one of the frameworks needs to be updated.
I would recommend to pick the framework that covers most of what you need, and try and add the missing features using plug-ins or own modifications.
Your question is too abstract.
For instance Zend Framework is more to be a library of specific functionalities ready-to-be-include into Your codebase then some closed development environment like for instance Symfony framework.
Thanks to it can be ZF simply included into your codebase (and Symfony too).
Symfony Framework compared to it is closed solution depending on front server environment so you cannot use it like some other framewor's slave.
It would really depend on which things you liked about both...
Zend Frameowrk is more like a library, so you can pick and choose components from it. Symfony also has some re-usable components you can use.
Really, you can do anything... it just depends how much work you want to do, and how willing you are to modify the framework code. Note: most other PHP frameworks are not nearly as flexible as Zend Framework (next up probably being Symfony).
This sounds very messy, so I'd advise against it, unless you use it in the fashion I've described above. It's easy to pull ZF or Symfony components into other frameworks, but not the other way around.
Hope this helps.
The composability of most frameworks is such that that is most likely to give you all the disadvantages of both, while simultaneously eliminating most of the individual advantages of both.
It seems to me like one framework will for serve as the core - bootstrapping, MVC stack, routing - while the other will be used to pull in specific functionality - like classes for forms or filtering or interacting with web services, etc.
As much as I prefer Zend Framework for the core - and most everything else - its use-at-will architecture argues for making the other framework the core and pulling in ZF components where you need them.
As #Adrian notes, it's easy to pull in ZF components into a project built primarily on another framework, since ZF is designed with that flexibility in mind. Other frameworks are less accommodating in this regard.
You can do it. Most modern frameworks (Zend, symfony, flow) is capable to use parts of other frameworks. Symfony 2 uses Zend Logger, flow3 uses sfYaml... It is possible tu interchange some components.
But, imho, you should stick to one framework as a core, and use second only to relatively isolated subsystems. Adapter and Facade design patterns can help you to mix them together - some components / clases demands some wrapping before use in non-native environment.
For further reading: http://www.symfony-project.org/book/1_2/17-Extending-Symfony#chapter_17_integrating_with_other_framework_s_components
Of course it is possible and I don't see something wrong with it. For example I used CakePHP and Zend on a relatively large Project which was kind of a cms. CakePHP for the core (Routing, MVC) and Zend for some "Modules". Mainly for PDF, E-Mail (smtp), FTP and a few others that CakePHP was not that good at. With Cake it was fairly easy to use ZF components and didn't feel hacky at all.
In fact, ZF was written to be as independent as possible, so that you can use any component at any time anywhere. Yet, it would not work the other way round (Using ZF as core, and Cake components). Surely it is possible, but a real pain with no benefits. So ZF could be used propably inside of pretty much any other framework and nothing would be wrong with it, imho.

PHP MVC framework for ASP.NET MVC/NHibernate developer

For class, I would like a to use PHP MVC framework very similar to ASP.NET MVC with NHibernate. I am very comfortable with ASP.NET MVC. I need to use PHP and MySQL. I would not like to be concerned with the SQL to save me time. I would like to just design my PHP model classes and controllers without all of that data-access logic behind it that I would have to write.
Any suggestions? Thanks.
Also, I'm very limited on what I can install on the server. For instance, I can't upgrade PHP or run other installers. I want something I can drop in.
I prefer Zend Framework MVC components combined with Doctrine if really want great power. but for something simple try CaKePHP as it has its own simple ORM implementation, and the framework is built to be the php version of Ruby on Rails.
My personnal preference for "MVC Framework" would probably be Zend Framework -- though it's not the only possible choice (I'm thinking about symfony too, for instance).
About the "not writing SQL" part, I would use Doctrine, which is a great ORM Framework.
It's actually the default ORM Framework of symfony, and can be used with Zend Framework quite easily.
I suggest Symfony. It uses Doctrine (which is inspired partly by Hibernate) too, but it is integrated deeper with Symfony than Zend Framework. Symfony provides a number of helper classes which really help automate things with Doctrine (my favorite is sfDoctrinePager). Zend Framework is a good choice, but I recommend looking at Symfony first. I would avoid the other PHP MVC frameworks as they tend to be less flexible, and if you're coming from another language you may have your own preferences on how to attack a certain problem - Symfony and ZF will both give you leeway in this sense.

Categories