yaf,全称 yet another framework,是一个c语言编写的php框架,[1] 是一个以php扩展形式提供的php开发框架, 相比于一般的php框架, 它更快,更轻便. 它提供了bootstrap, 路由, 分发, 视图, 插件, 是一个全功能的php框架。这节内容我们就来说说基于yaf的hello world示例,假设我的例子的站点目录为 /var/www/yaf_test ,我采用的目录结构如下:
- index.php //入口文件 + public |- .htaccess //重写规则 |+ css |+ img |+ js + conf |- application.ini //配置文件 + application |+ controllers |- Index.php //默认控制器 |+ views |+ index //控制器 |- index.phtml //默认视图 |+ modules //其他模块 |+ library //本地类库 |+ models //model目录 |+ plugins //插件目录
编写入口文件 index.php
<?php
//指向网站根目录
define("APP_PATH", dirname(__FILE__));
$app = new Yaf_Application(APP_PATH."/conf/application.ini");
$app->run();编辑 public/.htaccess重写规则(apache)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php编辑配置文件 conf/application.ini
[product] application.directory=APP_PATH "/application/"
编辑默认控制器 application/controllers/Index.php
<?php
class IndexController extends Yaf_Controller_Abstract{
public function indexAction(){
$this->getView()->assign("content", "Hello world");
}
}编辑视图文件 templates/index/index.phtml
<html> <head><title>Hello World</title></head> <body> <?php echo $content; ?> </body> </html>
经过以上操作,在浏览器输入网站127.0.0.1/yaf_test 就能看到Hello world的输出了, 如果不能,请再检查以上步骤是否做对!
以上就是一个简单的基于yaf的Hello world示例,如果大家有疑问欢迎咨询哦。
相关推荐:










