[DonkeyId] ;0-4095 donkeyid.node_id=0 ;0-Timestamp donkeyid.epoch=0 [yaconf] yaconf.directory=/tmp/yaconf ; yaconf.check_delay=0 [yaf] yaf.environ = product ; develop test yaf.use_namespace = 1 ; yaf.action_prefer = 0 ; yaf.lowcase_path = 0 ; yaf.library = NULL ; yaf.cache_config = 0 ; yaf.name_suffix = 1 ; yaf.name_separator = "" ; yaf.forward_limit = 5 ; yaf.use_spl_autoload = 0
把文件放到
/wwwroot/data_site/ysapi
server {
listen 80;
server_name api.local.com;
index index.html index.htm index.php;
root /wwwroot/data_site/ysapi/service;
if (!-e $request_filename) {
rewrite ^/(.*) /index.php/$1 last;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ /.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
127.0.0.1 api.local.com
http://api.local.com/index/index/index/data/def
http://api.local.com/ index/ index/ index/ data/def
域名/ 模块/ 控制器/ 方法 / 参数/值
若无问题,将看到:
之后就可以按yaf的方式开发API业务逻辑
业务代码开发完成后,我们可以reload或重启servers,来提供最新的接口
php /wwwroot/data_site/ysapi/run.php
服务启动无异常,可以使用api调用方法来尝试调用:
php /wwwroot/data_site/ysapi/call.php
try {
$api = new apicall();
$api->add('pagelist','index/index/index',['page'=>1]);
$api->add('user','index/index/index2',['user'=>1]);
$api->add('mess','index/index/index3',['mess'=>1]);
$rs=$api->exec('www');
$code=$rs['code'];
if($code!=200){
if($code==500){
// 全错
}elseif($code==300){
// 部份错
}else{
// 异常
}
}
$pagelist=$rs['pagelist'];
$user=$rs['user'];
$mess=$rs['mess'];
echo(print_r($pagelist,1));
}catch (Exception $e){
echo $e->getMessage().PHP_EOL;
die('ERROR-------------------------------'.PHP_EOL);
}
// /ysapi/_data/Index/Index.php
// 路径及名字按YAF的方式定义
class IndexData{
public static $indexAction=[
'def'=>[
'page'=>1
],
'p1'=>[
'page'=>1
],
'p2'=>[
'page'=>2
],
];
public static $index2Action=[
'def'=>[
'id'=>1
],
'u1'=>[
'id'=>1
],
'u2'=>[
'id'=>2
],
];
public static $index3Action=[
'def'=>[
'id'=>1
],
'm1'=>[
'id'=>1
],
'm2'=>[
'id'=>2
],
];
// http://api.local.com/index/index/index3/
// http://api.local.com/index/index/index3/data/def
// http://api.local.com/index/index/index3/data/m1
// http://api.local.com/index/index/index3/data/m2