YafYaf is a PHP framework similar to zend framework, which is written in c and built as PHP extension. Yaf是一个用PHP扩展形式提供的PHP开发框架, 相比于一般的PHP框架, 它更快. 它提供了Bootstrap, 路由, 分发, 视图, 插件, 是个一个全功能的PHP框架. you can refer to Yaf Manual(中文版, 中文版翻译滞后, 最新版本的文档, 还是请参看php.net上的英文版) for more informations. Pecl: yaf 1 InstallCompile Yaf in Linux$/path/to/phpize $./configure --with-php-config=/path/to/php-config/ $make && make install 2 Tutorial==layout==: A classic Application directory layout: - index.php //入口文件
- .htaccess //重写规则
+ conf
|- application.ini //配置文件
- application/
- Bootstrap.php //入口启动文件
+ controllers
- Index.php //默认控制器
+ views
|+ index //控制器
- index.phtml //默认视图
+ modules //其他模块
- library
- models //model目录
- plugins //插件目录index.phpindex.php in the top directory is the only way in of the application, you should rewrite all request to it(you can use .htaccess in Apache+php_mod) <?php
define("APP_PATH", dirname(__FILE__));
$app = new Yaf_Application(APP_PATH . "/conf/application.ini");
$app->bootstrap() //call bootstrap methods defined in Bootstrap.php
->run();rewrite rulesApache#.htaccess, 当然也可以写在httpd.conf
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.phpNginxserver {
listen ****;
server_name domain.com;
root document_root;
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^/(.*) /index.php/$1 last;
}
}Lighttpd$HTTP["host"] =~ "(www.)?domain.com$" {
url.rewrite = (
"^/(.+)/?$" => "/index.php/$1",
)
}application.iniapplication.ini is the application config file [product] ;支持直接写PHP中的已定义常量 application.directory=APP_PATH "/application/" default controllerIn Yaf, the default controller is named IndexController?: <?php
class IndexController extends Yaf_Controller_Abstract {
public function indexAction() {//默认Action
}
}
?>view scriptThe view script for default controller and default action is in the application/views/index/index.phtml, Yaf provides a simple view engineer called Yaf_View_Simple?, which supported the view template written by PHP. <html>
<head>
<title>Hello World</title>
</head>
<body>
Hellow World!
</body>
</htlm>Run the Applicatioinhttp://www.yourhostname.com/application/index.php 3 Classesit provide following Classes
|