我试图将一个解耦的wordpress/wp-api
集成到一个带有Twig视图的Slim 3框架。
/posts
路由
/post/hello-world
路线我现在有两个问题:
当我回复$body
时,我在视图中返回的JSON响应不是合适的JSON响应;
// ROUTES
$app->get('/', function ($request, $response) {
return $this->view->render($response, 'home.html');
})->setName('home');
$app->get('/posts/', function ($request, $response,array $args) {
$client = new Client();
$url ='/cms/wp-json/wp/v2/posts';
$res = $client->request('GET',$url,array(
'content-type' => 'application/json'
),array());
$body = $res->getBody();
// echo $body;
return $this->view->render( $response,'posts.html',array('posts' => $body));
})->setName('posts');
我真的想继续使用Twig和Slim而不是使用Vue.js或Angular来构建SPA。