Complete separation and development of front and rear end based on CodeIgniter framework

Source: Internet
Author: User
To use the CI framework to make a website, there are several requirements:
1. The front and back end is completely separated, and the foreground and background use the JSON format interface for data exchange;
2. Both front-end and back-end are independent projects, both in the foreground and in the background.
I do not know how to achieve this, I hope you are pointing out the following

Reply content:

To use the CI framework to make a website, there are several requirements:
1. The front and back end is completely separated, and the foreground and background use the JSON format interface for data exchange;
2. Both front-end and back-end are independent projects, both in the foreground and in the background.
I do not know how to achieve this, I hope you are pointing out the following

1th, in general, the controller through a series of database crud to get the data needed to display, loaded into the front-end template file, and then the template file rendering data will eventually display the full HTML page. To implement the way you say it, you need to change the controller's behavior: convert CRUD data into JSON format and print directly. At the same time, each static page of the front end requests different controllers to get the JSON data needed by Ajax, using JavaScript to place the data in each location in the HTML page, eventually displaying the full HTML page.

2nd, the front and back are independent of a project, can be easily understood as modular, front end, back end, even the blog part, the message section, the news section, the classification section, are a separate module. CI itself does not go through the overloaded core file implementation of this function is more troublesome, the simplest way is to use CI hmvc plug-in, each function into a separate module, each module contains a separate MVC part. In this way, the code for each module can be placed in its own separate folder in terms of the file organization structure. In addition to the database design, each module tries to use its own separate data table. The design of each module also uses loosely coupled mode as much as possible.

Provides a solution: divided into four application

后端apiProvides business logic encapsulation data processing
后台uiRender view that provides an interface to interact with the backend API
前台uiRender view that provides an interface to interact with the backend API
前端Bridging between foreground and backend APIs

Our present plan is H5+java SPRINGMVC. Using Swagger Oai Unified Interface Specification, front and back separation development, the frontend is not using the Webpack and other compiled JS, the backend did not use the attempt template. There are no professional tests on the backend, swagger UI. The front end uses a mock server.

If you use OAI to define restful api,swagger you can directly generate the interface code for the backend front end, there is also a 0code swagger-server current-side mock server. The backend SPRINGMVC also has a fully automated restful testing tool.

Of course you need to write OAI, the same kind of documentation and API blueprint

See if your project needs SEO, the best seo words or not to separate.
Separation is also the background to implement restful API, the front desk Ajax loading on the line.

The CI framework can be used without writing the view section, and each of the controller's public functions can be seen as an API invocation interface.
The foreground can select a UI framework +ajax to get the data.

Of course, Ajax access to data is no way to be found by the search engine (in fact, by some means is also possible), while using AJAX to get the data to display the browser must consider the forward and backward logic.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.