我正在尝试在我的 CakePHP 项目中使用Swagger-PHP ,但遇到了一些问题。有没有人设置这个?你有什么建议吗?我已经通过 Composer 成功安装了 swagger-php,它已加载到我的控制器中(见下文)。我正在尝试通过 Web 视图呈现规范,但我不太确定为什么没有填充注册表,或者是否需要填充。
以下是 ApiController.php 内部
use Swagger\Annotations as SWG;
use Swagger\Swagger;
public function swagger(){
$path = APP . 'Model'; //Path to the app directory
$swagger = Swagger::discover($path,APP . 'Model/Behavior');
debug($swagger);
//$swagger->jsonEncode($swagger->registry['/api']);
$swagResults = $swagger->registry;
debug($swagResults);
$this->set(array(
'results' => $swagResults,
'_serialize' => 'results'
));
}
结果
object(Swagger\Swagger) {
resourceList => array()
registry => array()
models => array()
[protected] fileList => array(
(int) 0 => '~/Sites/com/sitename-api/app/Model/[ModelName].php',
... All of my models
)
[protected] path => '~/Sites/com/sitename-api/app/Model'
[protected] excludePath => '~/Sites/com/sitename-api/app/Model/Behavior'
[protected] cache => object(Doctrine\Common\Cache\ArrayCache) {
[private] data => array(
'DoctrineNamespaceCacheKey[]' => (int) 1,
'[][1]' => 'a:4:{s:8:"registry";a:0:{}s:6:"models";a:0:{}s:4:"path";N;s:11:"excludePath";N;}',
'[cd9db43f54f6017ba1a20037c1577eb4d2017868][1]' => 'a:4:{s:8:"registry";a:0:{}s:6:"models";a:0:{}s:4:"path";s:56:"~/Sites/com/sitename-api/app/Model";s:11:"excludePath";s:65:"~/Sites/com/sitename-api/app/Model/Behavior";}'
)
}
[protected] cacheKey => 'cd9db43f54f6017ba1a20037c1577eb4d2017868'
}
所以,基本上 $swagResults 是空的,我猜这不应该是,对吧?