Yaf入门

基础

  • 官方手册
  • Yaf是一个C语言编写的PHP框架
  • 依赖SPL和PCRE扩展,一般PHP默认启用

优点

  • 性能开销小
  • 框架类在启动PHP时加载,常驻内存
  • 高性能的视图引擎
  • 可自定义视图引擎,支持插件,支持自定义路由

Hello World

结构

+ public
  |- index.php //入口文件
  |- .htaccess //重写规则    
  |+ css
  |+ img
  |+ js
+ conf
  |- application.ini //配置文件   
+ application
  |- Bootstrap.php
  |+ controllers
     |- Index.php //默认控制器
  |+ views    
     |+ index   //控制器
        |- index.phtml //默认视图
  |+ modules //其他模块
  |+ library //本地类库
  |+ models  //model目录
  |+ plugins //插件目录

入口文件

<?php
define("APP_PATH",  realpath(dirname(__FILE__) . '/../')); /* 指向public的上一级 */
$app  = new Yaf_Application(APP_PATH . "/conf/application.ini");
$app
->bootstrap()// 可选
->run();

重写规则

  • 每种server都要特别设置重写规则
  • 重写所有请求到入口文件
  • nginx为例
server {
  listen ****;
  server_name  domain.com;
  root   document_root;
  index  index.php index.html index.htm;

  if (!-e $request_filename) {
    rewrite ^/(.*)  /index.php/$1 last;
  }
}

配置文件

  • 可以直接使用php中已定义的常量
  • 配置文件支持继承, 支持分节
  • 默认节是product
[product]
application.directory=APP_PATH "/application/"

引导程序

  • yaf提供的一个全局配置的入口, 可以做很多全局自定义的工作
class Bootstrap extends Yaf_Bootstrap_Abstract{
   

}

默认控制器

  • 默认控制器为IndexController
  • 默认Action为IndexAction
<?php
class IndexController extends Yaf_Controller_Abstract {
   
   public function indexAction() {
   //默认Action
       $this->getView()->assign("content", "Hello World");
   }
}

默认视图文件

  • yaf支持简单的视图引擎
  • 默认视图文件为views/index/index.phtml
<html>
 <head>
   <title>Hello World</title>
 </head>
 <body&g
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值