PHP 框架,第 2 部分: 构建样例应用程序
“PHP 框架” 系列将介绍三个广泛使用的 PHP 框架 —— Zend、symfony 和 CakePHP —— 通过在三个框架中构建和扩展样例应用程序,研究三个框架的类似之处和不同之处。第 1 部分将列出本系列涵盖的内容并且配置先决条件。在第 2 部分中,您将分别在三个框架中构建样例应用程序。
在本系列的 第 1 部分 中,我们已经设定了本系列的范围并满足了先决条件。现在,将分别在三个框架中构建样例应用程序。在接下来的几篇文章里,将扩展应用程序、了解不符合常规的例外情况、使用 Ajax、集成外部任务等等。
本文将指导您分别在三个框架中创建样例应用程序 Blahg。您将从头做起,了解在 Zend 框架、symfony 和 CakePHP 中开发简单应用程序的基础知识。
您应当已经完成了 第 1 部分,该部分介绍了如何安装这三个框架及使用三个框架必须满足的先决条件。如果您还未读过这一部分,则应立即阅读。
假定您已经了解 PHP、应用程序设计以及如何在数据库中工作。您不需要具有框架使用经验,但是您应当已经准备好开始使用框架。
在 Zend 框架中构建 Blahg
首先,创建目录 /column/htdocs/zend 和 /column/protected/zend。这些目录将分别保存 Web 可访问的文件及 Web 不能访问的应用程序文件。在 /column/htdocs/zend 中,用以下命令行创建一个 .htaccess 文件:
RewriteEngine onRewriteRule !.(js|ico|gif|jpg|png|css)$ index.php Copy after login |
在涉及目录结构时,每个框架都有自己特定的要求。对于 Zend 框架,需要创建目录 /column/protected/zend/controllers、/column/protected/zend/models 和 /column/protected/zend/views 来保存控制器、模型和视图。此外,需要创建目录 /column/protected/zend/views/scripts;并且对于每个控制器,需要创建一个目录来保存一些视图。例如,您知道 Blahg 将需要为 post 控制器提供一些视图,那么就需要创建目录 /column/protected/zend/views/scripts/post 来保存该视图。
已经准备好目录。该来构建模型了。
构建 Zend posts 表和模型
在第 1 部分中,创建了将要使用的 posts 表。如果您跳过了那段内容,请立即查看并且创建该表。该表的模型非常简单。它应当被命名为 Posts.php,并且应当在 /column/protected/zend/models/ 创建它。Posts.php 将扩展 Zend_Db_Table
类,并且您将使用的大多数方法均继承自该类。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

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

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
