Yii framework for building API's - php

I have been working with Yii for some years, since version 1. I think is an awesome framework.
Today I need to build a website using Yii which includes building an API, administrator and frontend site.
In the past when I have worked in other similar projects. I shared model between them, each side (api, frontend and administrator) have their own controllers.
With Yii I am trying to find a way to organize it to take advantage of the full power of yii.
I was planning to use API only for mobile apps not for web frontend to be able to use Yii validation rules, etc and speed up the project.
Project owner wants to build a frontend which reads data through API too, that will bring duplicated validation rules etc.
If I follow project owner requirement it will be like managing 3 projects
1. Api + Backend
2. Frontend
3. Mobile
If I follow the other option, it will be like managing 2 projects:
1. API + Frontend + Backend
2. Mobile
Any advice?

Use the advanced application template, make the common directory a git subtree. Then, you can use the subtree in any number of projects. There you are maintaining only one set of models for several applications. Works great for me.

Related

How to change a symfony project from mvc to client-server architecture?

I recently started learning PHP and Symfony 4 and I developed an app. Now my next task is to change the architecture of the project, from MVC to client-server. More exactly, I need to have my templates and controllers in an application and the business logic in another application. Any ideas how I can do this? I can't even figure out how to run 2 different symfony projects simultaneously.
A client-server application is an application base on a communication model call client-server: wiki
MVC is a way to develop and structure application: wiki
But i understand your needs. You want to keep a symfony app but you also want to put all the logic view and front end features into a separate app (like React or Vue)
Your Symfony App will still use MVC pattern, just you'll replace what the controller give to the view.
The best way is to turn the Symfony App into API with normalize view data like JSON or XML. Those data will feed your front app.
To achieve this you can use this bundle, which turn your model layers into API: API Platform

Application Skeleton for YiiFramework

I am looking for a skeleton application for the YiiFramework to get me up-and-running with a simple PHP application I would like to build. Some requirements are:
A login/authentication system that keeps the current user's session state (and is secure from injection attacks, etc).
It connects to a back-end database (MySql).
Has an example table display that demonstrates CRUD operations. i.e. List records from a specific table, a form to edit a specific record as well as pagination and basic search filter.
A menu framework that can be easily added to.
(Ideally) A pre-existing, visually appealing theme.
(Ideally) Has a structure that supports language localisation.
(Ideally) Has a framework for a REST API.
I have seen https://github.com/clevertech/yiibooster which provides a nice set of components that would take care of these requirements, however from what I understand, all the above would still need to be assembled. I know that the YiiFramework is designed to make quick work of this, however I have never used any of these frameworks before and would learn much quicker from a pre-existing example/template (and/or existing Yii application) rather than going through the documentation.
Any help appreciated.
As mentioned by #Bizley, Yii2 Advanced Project Template is a very good starting point to learn the concepts & get hands on with Yii2.
There are several other Yii2 templates available & most of them have been developed by customizing and/or adding features to the Yii2 Advanced Template. Just for your reference here are some Yii2 templates (in no particular order) -
yii2-improved-advanced-template
http://www.yiiframework.com/extension/yii2-improved-advanced-template/
Introduction
Yii2-advanced-template is based on yii2-app-advanced created by yii2
core developers. There are several upgrades made to this template.
This template has additional features listed in the next section.
Application structure has been changed to be 'shared hosting
friendly'.
Features
Signup with/without account activation
Login using email/password or username/password combo.
Rbac tables are installed with other migrations when you run yii migrate command.
Users with editor+ roles can create articles.
Session data is stored in database out of the box.
System setting are stored in config/params.php file ( changes from v2 ).
Theming is supported out of box.
Translation is supported out of the box.
Administrators and The Creator can manage users ( changes from v2 ).
Password strength validation and strength meter.
All functionalities of default advanced template are included in this template.
Code is heavily commented out.
Yii2 Practical App
http://demos.krajee.com/app-practical
Why yii2-app-practical?
After installing a app in the yii2-advanced application you normally
would access the frontend from http://domain/app/frontend/web.
However, in many practical scenarios (especially on single domain
hosts) one would want their users to directly access frontend
as:http://domain/app
The yii2-app-practical enables you to achieve just that by carefully
moving and rearranging the bootstrap files and web components of
frontend to work directly out of the app root. The frontend/web is
entirely eliminated and one can directly access the application
frontend from http://domain/app
All other aspects of the app configuration remain the same as the
yii2-advanced app. The common, backend and console will remain as is.
The frontend config, assets, models, controllers, views, widgets and
components, will still reside within the frontend directory. It is
just the web access that is moved out to app root.
Yii 2 Starter Kit
https://github.com/trntv/yii2-starter-kit
This is Yii2 start application template.
It was created and developing as a fast start for building an advanced
sites based on Yii2.
It covers typical use cases for a new project and will help you not to
waste your time doing the same work in every project
FEATURES
Beautiful and open source dashboard theme for backend AdminLTE 2
Translations: English, Spanish, Russian, Ukrainian, Chinese
Translations Editor
Language change action + behavior to choose locale based on browser preferred language
Sign in, Sign up, profile(avatar, locale, personal data), email activation etc
OAuth authorization
User management
RBAC with predefined guest, user, manager and administrator roles
RBAC migrations support
Content management components: articles, categories, static pages, editable menu, editable carousels, text blocks
Key-value storage component
Application settings form (based on KeyStorage component)
Ready-to-go RESTful API module
File storage component + file upload widget
On-demand thumbnail creation trntv/yii2-glide
Command Bus with queued and async tasks support trntv/yii2-command-bus
Useful behaviors (GlobalAccessBehavior, CacheInvalidateBehavior, MaintenanceBehavior)
Yii2 log web interface
Application timeline component
Cache web controller
Maintenance mode component (more)
System information web interface
dotenv support
ExtendedMessageController with ability to replace source code language and migrate messages between message sources
Aceeditor widget
Datetimepicker widget,
Imperavi Reactor Widget,
Elfinder Extension
Xhprof Debug panel
Extended IDE autocompletion
Nginx config example
Test-ready
Docker support and Vagrant support
Built-in mailcatcher
Assets compression and concatenation
Some useful shortcuts
many other features i'm lazy to write about :-)
I guess these should be more than enough to get you started.

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

How to create an API-centric application (more specifically: for HMVC in CodeIgniter)

Background:
I am working on a web application, that I plan to launch with iPhone and Android versions in the near future, and I have some questions about developing an API for use by the different front-ends.
I Started with This:
I was reading this TutsPlus tutorial, which talks about creating an API-centric web application, meaning that all of your browser calls and smartphone app calls are routed through the API.
What especially got me excited, was this statement in the tutorial from Twitter:
One of the most important architectural changes is that Twitter.com is now a client of our own API. It fetches data from the same endpoints that the mobile site, our apps for iPhone, iPad, Android, and every third-party application use.
The above statement reflects, what I would ideally like to create.
Then I Saw This:
I found this TutsPlus tutorial, which talks about, how to build a REST API for CodeIgniter. This was good, because I am developing my application in CodeIgniter, using the Modular Extensions plugin - HMVC, and I thought it would be perfect for my purposes.
The only thing, that I'm somewhat lost in, is the way Phil Sturgeon seems to suggest to create the API. He suggests to have all of your front-end code modules completed and then create an API for each of the modules in their respective directories (not necessarily in that order). This would be fine if I didn't want it to be API-centric.
And I Want to Know How to Do This:
How should I proceed to get a blend of both tutorials:
API-centric application that can be used by a browser application as well as separate mobile applications
REST API for CodeIgniter (with HMVC modules)
Should I:
Just follow the API-centric tutorial and try to tailor it to my needs?
Follow the CodeIgniter-specific tutorial and use Phil Sturgeon's advice for how to implement it with HVMC?
A combination of both?
Neither?
Take a look at Eating your own Dogfood by Nick Jackson. These are slides from CICONF 2012 where he details how this all works.
Building your API first is a great idea, then your application can use the API to fetch the data itself. This is of course a little slower as you're adding a HTTP request on data, but locally its not too bad and if you use HMVC to make the request it's even quicker.
In the tutorial I didn't get into HMVC because it's an extra subject, but it can be awesome for adding modular API's. In some simple applications I just make a /api folder like the tutorial suggested but PyroCMS Professional has an API module and a sexy route to allow modular API stuff:
$route['api/([a-zA-Z0-9_-]+)/(:any)'] = '$1/api/$2';
$route['api/([a-zA-Z0-9_-]+)'] = '$1/api/index';
This means I can have a "api.php" controller in every module and still use the /api/controller/method syntax or even /api/controller if you have function index_get().
I would strongly suggest you grab PyroCMS Professional for this feature. Yep you gotta pay, but it handles user key generation, authorisation, logging, etc all out of the box and handles your website too.

How would I integrate existing zend FW apps into 1 application?

An existing 8+ year old application is being migrated from a self-contained website to a webservice-oriented architecture to allow among other things, external parties access to the calculations and data within the application.
The application allows visitors to access insurance-related information, calculate price quotes and contact agents.
The original logic of the application has been extracted from the main application to a SOAP service - so far, so good.
Based on in-house knowledge of Zend FW, the choice was made to drop the legacy code with many downsides and move to a more robust and community-backed framework - Zend.
An initial Zend FW app has been built that consumes the WSDL and allows searching and displaying of customers. After that was finished we wanted to integrate external applications/modules for components such as a basic (!) cms, mass-mailings, polls etc.
As we consider those components essential for the end-product but not our own core-product, we thus want to use external applications for this.
However - looking at e.g. tomatocms and digitalus etc., they seem to require us to build our product into theirs - and we want it the other way around. CMS pages are the exception, and not the rule.
Integrating authentication among these applications seems very difficult, as each seems to want to be 'the' application.
TL;DR:
What would be the best solutions to integrate a CMS or other apps into an existing/in progress zend FW app?
I think the best solution for you is to create a structure for Modules/Plugins where you set a pattern of use and you will make your application understand these modules created following the specifications above.
With this you allow anyone to be creating or developing models desaclopados their application.
I think this is a good example with your Wordpress plugins. Anyone can create and embed its functionality within the application page, but of course you can make in its API limitations, controlling what you want.

Categories