php Recess framework入门
Recess安装:
#install:unzip recess-v0.20.zip to apache DocumentRoot (/var/www/html)#install PHP 5.3.3yum install php53-pdoyum install php53-mysql
Recess框架介绍
Recess是一个开源的,轻量级的RESTful PHP framework;它的应用分为3大块Models、Views和Controllers, 分别和MVC模型对应;
一个application默认放在/apps下面。Recess框架可以同时处理多个应用。在apps下面是应用的子目录,形如:/apps/{appName}/,如:
具体应用的配置appNameApplication.class.php,必须继承框架的Application类
框架配置项
位于框架配置文件recess-conf.php;
具体应用配置需要添加到配置项RecessConf::$applications中
数据库配置为RecessConf::$namedDatabases
Controllers和Views:
默认执行流程,先选择(route)一个控制器(即应用的控制器类)方法执行,然后再选择一个视图view作为响应HTTP的response
1. 控制器Controller负责是指使用哪一个视图view模板。
2. 默认的应用控制器文件为apps/appName/controllers/appNameHomeController.class.php
3. 控制器方法中调用视图$this->ok(‘view-name’)
4. 控制器中的变量,默认会传递给同名的视图
5. 控制器的方法如果没有调用exit,则默认回去调用和方法同名的一个视图view
6. 控制器Controllers可以通过变量来给视图Views传递数据视,如控制器appNameHomeController.class.php中有如下方法modetest:
/** !Route GET,/m */function modetest() { $this->viewdata = 'will pass view modetest';}
则视图modetest.html.php中调用变量viewdata为:
<html><p>this is view</p><?phpprint $viewdata;?></html>
路由route及路由注解:
route在控制器里面完成,把接收到的请求URL分发到应用的具体点(控制器的方法)来处理,具体形式是通过route注解来完。route注解RouteAnnotation语法形式为:
/** !Route HTTP-method, URL-path */
有2个参数,第一个HTTP-method是HTTP的方法,如GET, POST, PUT, or DELETE;
第二个参数URL-path是URL路径部分,如果包含”$“符号,则会变成相应方法的参数method parameter
URL-path如果没有,则默认的访问形式appName/methodName
class TestController extends Controller { /** !Route GET */ function index() { echo 'Hello PHP Community!'; exit; } /** !Route GET, /hello/$first/$last */ function aMethod($first, $last) { echo "Hello $first $last!"; exit; }}
Model模型
和数据操作相关,实现数据库的CRUD操作。通过include到controller控制器中就可以使用
应用管理工具
Recess框架自带了帮助工具,可以用来创建和管理应用,其访问路径为http://{$installUrl}/recess/
如果要查看应用的所有RESTful接口,则访问http://{$installUrl}/recess/apps/appNameApplication
参考
The Book of Recess Official Guide to the Recess PHP Framework
Apache mod_rewrite配置

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

Alipay PHP...

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,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

The enumeration function in PHP8.1 enhances the clarity and type safety of the code by defining named constants. 1) Enumerations can be integers, strings or objects, improving code readability and type safety. 2) Enumeration is based on class and supports object-oriented features such as traversal and reflection. 3) Enumeration can be used for comparison and assignment to ensure type safety. 4) Enumeration supports adding methods to implement complex logic. 5) Strict type checking and error handling can avoid common errors. 6) Enumeration reduces magic value and improves maintainability, but pay attention to performance optimization.
