Table of Contents
回复内容:
Home Backend Development PHP Tutorial php不使用模版,怎么实现前端和后端人员的协作开发?

php不使用模版,怎么实现前端和后端人员的协作开发?

Jun 06, 2016 pm 08:41 PM
php front end stencil

如题:
模版的初衷是:代码与页面的分离。但实际开发过程中, 模版文件页面元素要嵌入大量的变量,以及同时处理if/else、for each等处理逻辑,比如smarty模版。
对于这种模版文件,模版语言和html语言混合在一起,结构混乱、逻辑与布局混杂,既不利于编辑制作,也不利于调试排错。同时还要增加前端人员的学习压力(例如要学习smarty)。

理想的模式下,前端只负责展示和交互(html/css/js),后端只负责提供数据(php)。

怎么实现这种理想模式?

回复内容:

如题:
模版的初衷是:代码与页面的分离。但实际开发过程中, 模版文件页面元素要嵌入大量的变量,以及同时处理if/else、for each等处理逻辑,比如smarty模版。
对于这种模版文件,模版语言和html语言混合在一起,结构混乱、逻辑与布局混杂,既不利于编辑制作,也不利于调试排错。同时还要增加前端人员的学习压力(例如要学习smarty)。

理想的模式下,前端只负责展示和交互(html/css/js),后端只负责提供数据(php)。

怎么实现这种理想模式?

今天刚看到一个地方说,可以使用JQuery,前端所有数据通过JQuery的Ajax进行获取数据,以及进行前后端数据的交互。

后端输出json,前端处理数据

用这个模式写过一些东西,希望有帮助

博客 http://i.mouto.org/
博客 http://mouto.org/

讨论版 http://za2.org/

电台 http://itorr.sinaapp.com/fm/
电台 http://moe.re/fm

个人吐槽记录 http://x.mouto.org/

照片社区 http://dev.vscam.co/


2015-2-20: ......这么多从这里来路的访问为什么不慷慨下鼠标给个赞!!!!!!! T_T

楼上正解,后台使用json传送数据 前端使用ajax接收。

  • 使用JSON
  • noBackend

我先谈谈我的观点。

PHP最开始最初的嵌入HTML中, 后来模板盛行(如Smarty), 再到后来的又抛弃模板(使用用输出)或轻量级模板(如Laravel的Blade模板引擎)。但前后台代码始终没有做到完全分离。作为Web开发的神级架构MVC, 有的时候让人搞不清楚业务代码究竟应该写在哪, 所谓的视图就是套着php锁链的HTML, 而Model大多数是一个继承于ORM的子类。这样的模式, 后端开发人员仍要处理HTML代码。就算是一个人在写前后端, 也要不断的切换思维,徘徊于业务逻辑和View之间, 实在是很痛苦。

单纯的后端只输出JSON, 前端处理JSON并显示, 确实可以做到前后端的分离。但是没有条条框框束缚的开发模式,工程很容易随着工程量的增加或代码的不规范而陷入泥沼。

我现在十分推崇纯粹REST后端 + AngularJS(REST)前端的架构。纯粹REST后端, 完全抛弃的View,并且可以凭借单一后端支持主流的应用场景: App, 浏览器, Web API,最主要的是有那么一套规范或标准实现去约束你,后端人员只需考虑如何更rest,更好的写易于使用的API就好了。而AngularJS从REST后端手中接过大棒,可以轻易的实现一个很优雅的前端架构。

再辅以node.js,单元测试,coffee, sass之流 .... 想不爽都难

模板的實質是 placeholder。你連 placeholder 都不寫,計算機怎麼知道什麼是可變的什麼不可變?結果至多是把模板邏輯挪到代碼里,然後代碼高度依賴 html 結構。。。回到石器時代。。。模板從有 if-else 開始就跑偏了,越來越想媲美一個通用語言,越來越複雜。

或者把模板啥的一股腦推給前端,後端只做 API,但這樣只是責任轉移了,前端依舊不能專心負責展示和交互。

其實後端應該分兩類,一類負責核心應用,一類負責模板
HTML CSS 依舊叫前端負責

前後端的分法本來就有些欠缺,缺少一個中間層。

只有這樣,才有可能做到:

前端只负责展示和交互(html/css/js),后端只负责提供数据(php)。

因爲前後端銜接的任務交給中間層了~

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles