Recently, we have to build a project with both clients and web Front-ends. The YII framework is used. The web Front-end is okay to say that the echo directly in the html code, sometimes even directly echo the html statement, but this is not compatible with the Android client. Could you tell me how I can achieve web-based and client-based services? Recently, I want to build a project with both clients and web Front-ends. The YII framework is used. The web Front-end is okay to say that the echo directly in the html code, sometimes even directly echo the html statement, but this is not compatible with the Android client. How can I use the same server code on the web and client?
Is json used? Asking for advice, sincerely asking for advice
Reply content:
Recently, we have to build a project with both clients and web Front-ends. The YII framework is used. The web Front-end is okay to say that the echo directly in the html code, sometimes even directly echo the html statement, but this is not compatible with the Android client. How can I use the same server code on the web and client?
Is json used? Asking for advice, sincerely asking for advice
UseAPI
Mechanism, regardlessweb
End ormobile
End, all goAPI
To retrieve data.
Since we useYII
, You can usebehavior
Mechanismhandle
Manystuff
.
For example, defineAPIBehavior
To Format and process data.
However, since the subject wants to use a set of mechanisms for processing, it is necessary to ensure that the requirements are consistent. Otherwiseweb
Needs to be modifiedAPI
, Thenmobile
.
Of course, you can put most of the logic in oneBaseAPI
And then place the alienated code inMoblieAPI
AndWebAPI
.
How to designRESTful API
Refer:
Best Practices for Designing a Pragmatic RESTful API
StephenLee
It is clear that the interface is used to transmit data (josn), and the mobile end and the web end are rendered on the front-end js in the page. The only difference is the css layout. Some features may be removed from the mobile terminal or designed separately. Json is only the data transmission format. rest is the data transmission protocol for your interface. You can use css frameworks such as boostrap3.0, but the support for earlier ie versions is very general.
I like angularjs, which is basically the same as echo. For example, the data is an object. item. name, As long as {object. item. name}. It encapsulates the template of handlebarjs. foreach and ifesle can be easily implemented. Of course there are still many js frameworks, and even jquery can be used directly.
I guess the subject development team is not strong either. I have one or two people at the backend in the previous section. I personally think backbone is a little heavy, after comparing ember and angular with backbone, I think backbone is the most important in code development. The simplest is angular :)
I am afraid to accept this because I have recovered so much separately. Give me a compliment.
Are web and Android clients all browsers? You can try bootstrap. a css/HTML framework should solve your compatibility problems.
The web Front-end can try mvc, such as ember. js and angular. js frameworks.
It is best to use a responsive front-end framework such as bootstrap. Then you can check the phonegap
The web end uses angular. js and the mobile end uses bootstrap.