Best way to build RESTful services using Zend Framework 3 - php

We are starting a new project that will make use of RESTful services to talk to web clients (AngularJS) and mobile platforms (Android and iOS).
The idea is to hide the bussiness logic inside the RESTful services and to use the same code for both web client and mobile platforms.
Our server is being built in PHP using Zend Framework 3 (I´m new to the framework). The application will be have dozen of entities with hundreds of services.
I´ve noted on the web that is seems that ZF2 has a REST module, but I can´t find one for ZF3 (at least not in the documentation).
Some questions I have:
What is the best path to provide RESTful services using ZF3 ?
Shall I install a ZF module ? Is there something ready to be used that comes with ZF3 ?
Shall I create a Module in the code just for my services ? Shall the other
modules call this REST module for business logic ?

ZF3 is still shipped with an AbstractRestController, which can be found here. Apigility could be a starting point for your REST application, but you could also consider implementing only some parts of Apigility and build your own logic on top of that. Interesting modules can be found in the ZF-Campus GitHUB repository:
ZF-Rest
ZF-Content-Negotiation
ZF-Content-Validation
ZF-Hal (depending on whether HAL-Json works for you...)
Most (if not all) of those modules are refactored to support ZF3 (and backwards compatible with ZF2).
Browse through the repository yourself because you might find additional useful modules.

Related

Ready made PHP modules

Are there any frame work / modules that I can use when building web apps from scratch (php, sql)?
I am sure that coders don't write login, signup, etc. features (of typical web 2.0 apps) from scratch, they got modules that they refer to / reuse.
Is there a possibility to gain access to those modules to use?
Thanks
I'm not exaggerating but there might be a thousand PHP frameworks. All you have to do is to google PHP Frameworks .
Some well known ones are :
Laravel
CakePHP
CodeIgnitor
Yii
Symfony
Zend
... and the list goes on and on
you can use laravel if you have basic concept about php and mvc framework you will be able to control over laravel very well, when you create module it will gives you crud methods by default you just have to get an idea about its namingConvention and use. please visit https://scotch.io/tutorials/simple-laravel-crud-with-resource-controllers

RESTful API and versioning in Zend Framework 2

I created a RESTful API in Zend Framework 2.1 but I still don't know what is the best approach to make versioning for this API. I also use the doctrine as a model part of my app. I'd like to have links like that:
api.name-of-my-project.com/v1/products
api.name-of-my-project.com/v1/products/123
where v1 describes the version of API.
So far I already created API without versioning and I also have some ideas about how to create versioning but first I'd like to know your opinions about this problem. What should I do to separate controllers and maybe other classes from different versions and how to manage the routing? By the way I think that I am not really interested about creating another module because I already have module like API.
The final app should be able to work with "many" versions of API. I'd like to also inherit some functionality from older version of API in my new one.
You can do this with zf2 routing array in your module config
Map routes with v1 to versiononecontroller and v2 to versiontwocontroller

Zend framework installation - need clarification

I've seen lots of videos and instructions on how to install zend framework on wamp and other similiar local host environments. I've also seen lots of references, including here, that mention you don't need to 'install' zend, it just needs to be included in the php files to work.
As I think I understand it, installing zend on localhost environments will allow you to utilize certain tools that for example automate the creation of projects and gets the most out of the framework. I'm assuming that to then use these projects in a web host environment, you simply need to upload a specific project's files and ensure the zend files are in place and included in the directories.
Are my assumptions correct? I'm still trying to grasp the basics of this one and haven't found clarifications in my google searches.
Everything you wrote is correct. It helped me to think of Zend Framework as a library of components rather than as a program you need to install. As long as your application has access to that library of components, Zend Framework is installed. This doesn't address any of the configuration tasks you'll need in Bootstrap and/or application.ini, but should clear up installation.
Regarding the automated creation of projects and project elements (controllers, actions, etc.) this feature is available via Zend_Tool and is typically used only during development, so it shouldn't come into play once you've ported from your localhost.
Automated creation of the projects is far not the main feature of Zend.
The majority of the php frameworks are about providing the best infrastructure for complying to MVC design pattern, about object relational mapping, security enhancements etc.
And yes, the whole project tree is what you'd need to carry around for deployments.

Best way to package a general-purpose zend module

As our company starts using Zend Framework as the base framework for most of our projects, we want to share some common elements across all our projects. I talk about things like:
An implementation of a model (based on doctrine2)
RBAC for the model, including user, group, role models
A xml-based templating engine for ajax backend interfaces
(you name it) ...
Basically, all things to put "zend on rails" and get going. What is the best way to package these components? I see two possibilities:
As modules
We include the necessary functions as separate modules into the modules folder.
Pro:
We can set routes and execute code, which is good for many modules (imaginary example: a paypal module needs some kind of callback url. If our module can set it up on its own, no configuration from the "project developer" is needed).
We can provide real functionality (like the user administration) out of the box
We have a bootstrap to set up autoloading and doctrine etc.
Con:
Bad place? Interferes with the users project
A little harder to share between projects (git submodules instead of classpath)
In the library folder
We put it in the library folder and point the classpath to it.
Pro:
Clean solution
Sharing across projects
Con:
Bootstrap has to be explicitly called
No direct routing or actions - everything has to be proxied through the concrete project
So, how do you solve this? Where do you put your reusable, general purpose stuff in zf?
I think you should use both approaches.
When developing "library-like" code, as in kind of "infrastructure" classes and other things that are reusable (like ZF's own components, Doctrine 2's components etc.), you can put them into the library directory. (or its own entirely separate project)
When developing actual ZF modules (like an auth module for example), then format the code around the ZF module structure.
I think by using this kind of approach you get all the benfits you listed, and pretty much none of the cons :)
As one additional idea, if you develop your architecture parts as "services", you could even keep them running as their own web service endpoints.

What is the best way to create a "fully" modular ZF-based application?

For the past time I have been working on a Zend Framework based webshop application that we are building from scratch. The application has been successfully been set up for several clients, but we are stumbling upon more and more problems regarding extensibility and modularity of the application.
A lot of clients require a lot of different approaches on some matters, often requiring customizing default modules or extending them. I have been looking on the web for Zend Framework based code that could guide me to this and so far Magento has been the only example I have come up with. Although Magento seems to do a very good job offering extensibility and modularity, the code is far too complex and extensive for my current needs (or so it seems).
In an ideal situation, it would work as follows:
Each client gets the "base" application installed
Modules, controllers, models should be easily overridden or extended
New modules should be easily created
Are there any other Zend Framework based applications or other pointers that could guide me in the right direction?
Thanks in advance.
I think version 1.8 of the Zend Framework is going to address a lot of the issues with building modular applications. Especially with the new (Zend_Application) it should allow for auto loading of module resources, which isn't easy to do at this point.
I don't know much about it, but this may be something to look into. 1.8 should be out by the end of this month.
Zend Framework is a... framework. What you're looking for is a full blown system. That's your job as a developer is to build a system on top of a framework (whether Zend or your own).
People usually tell you not to reinvent the wheel, but in this case you need to develop your own system for your company to easily be able to develop and deploy for new clients.
Like already stated, it is a very complex answer you are looking for. You will not get that answer.

Categories