安装 yaf
https://github.com/laruence/yaf
使用git 下载源码包 git clone https://github.com/laruence/yaf.git
也可以下载这个安装包
进行解压 然后进入 tools/cg 目录文件夹 使用 yaf_cg 进行生成目录。
通过命令去生成框架目录的时候,有两种方式,
一、使用命名空间
./yaf_cg napi napi n
第四个参数是 n 代表使用命名空间。
使用命名空间,php.ini 还需要进行配置
vim php.ini
yaf.use_spl_autoload=1 yaf.use_namespace=1
增加如上配置

二、不支持命名空间
./yaf_cg web
查看一下目录 cd output 目录
tree web

代码执行成功后,这是一个最基本、最简单的项目。
下面是服务器,需要进行配置的代码,选择自己适用的,配置好,重新启动服务器:
Rewrite rules
Apache
#.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.phpNginx
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;
}
}Lighttpd
$HTTP["host"] =~ "(www.)?domain.com$" {
url.rewrite = (
"^/(.+)/?$" => "/index.php/$1",
)
}我本地使用的是 nginx 那么来配置一个nginx 来试试看:
server {
listen 8059;
client_max_body_size 100m;
server_name localhost;
index index.php index.html;
root /usr/local/nginx/html/api;
#error_page 404 = /404/index.html;
location / {
root /usr/local/nginx/html/api;
index index.php;
}
if (!-e $request_filename) {
rewrite ^/(.*) /index.php/$1 last;
}
location ~ .*\.(jpg|jpeg|png|gif|js|css)$ {
expires 1d;
}
location ~ \.php(/|$) {
fastcgi_pass 127.0.0.1:9007;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
运行结果:

到这里,最简单的yaf框架,已经运行起来了。
可以下载这个最简单的yaf 框架进行扩展业务。