第 3 章 快速开始

本章将给出关于 Yaf 的快速使用手册.

3.1. 需要些什么?

假设Yaf已经正确编译, 安装.

典型的应用目录结构

在开始之前, 先给出一个典型的Yaf应用目录结构, 后面的示例都会基于这个结构:

一个典型的应用目录结构

- .htaccess           // 重写规则
+ public/
  | - index.php       // 应用入口
  | + css/
  | + js/
  | + img/
+ conf/
  | - application.ini // 应用配置
- application/
  - Bootstrap.php     // 引导
  + controllers/
     - Index.php      // 默认控制器
  + views/
     |+ index/
        - index.phtml // 默认动作的视图模板
  + library/          // 类库
  + models/           // 模型
  + plugins/          // 插件


将Web服务器的DocumentRoot设置为public目录, 这样从Web就只能访问到公开资源.

对于多模块的应用, 每个模块在application/modules/<ModuleName>/下都有自己的controllersviews目录:

多模块应用的目录结构

+ public/
+ conf/
+ application/
  + modules/
    + Index/       // 默认模块
      + controllers/
      + views/
    + Admin/       // 另一个模块
      + controllers/
      + views/
  + library/
  + models/
  + plugins/
  - Bootstrap.php


已注册的模块需要在配置项application.modules中声明.