本文整理汇总了PHP中Slim\Http\Response::withJson方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::withJson方法的具体用法?PHP Response::withJson怎么用?PHP Response::withJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\Http\Response
的用法示例。
在下文中一共展示了Response::withJson方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUserDetails
public function getUserDetails(Request $request, Response $response, $arguments)
{
$user = $this->container->user;
if ($user) {
return $response->withJson($user, 200, JSON_PRETTY_PRINT);
}
}
示例2: render
/**
* @param Response $response
* @param int $status
*
* @return ResponseInterface
*/
public function render(Response $response, $status = 200)
{
// Put the default top-level members into $result object
$result = new \StdClass();
$result->data = $this->data;
$result->errors = $this->errors;
return $response->withJson($result, $status);
}
示例3: listFeeds
/**
* @param Request $request
* @param Response $response
* @return Response
*/
public function listFeeds(Request $request, Response $response)
{
$list = $this->getModel()->getCondensedList();
$feeds = [];
foreach ($list as $feed) {
$feed->id = $feed->_id->__toString();
$feeds[] = $feed;
}
return $response->withJson($feeds, 200);
}
示例4: render
public function render(Response $response, $code, $data)
{
if (is_array($data)) {
foreach ($data as $key => $value) {
$data[$key] = $this->_checkForParsing($value);
}
} else {
$data = $this->_checkForParsing($data);
}
return $response->withJson($data, $code);
}
示例5: index
public function index(Request $request, Response $response, array $args)
{
/** @var Careers $career */
$career = $this->data(Careers::class);
/** @var \PDOStatement $portfolio */
$portfolio = $this->data(MemberPortfolios::class)->find(['member_portfolio_id' => (int) $args['id'], 'user_id' => $this->session->get('user_id'), 'deleted' => 'N']);
if ($request->isXhr()) {
return $response->withJson($portfolio->fetch());
}
$this->view->addData(['career_levels' => array_pairs($career->getLevels(), 'career_level_id'), 'industries' => array_pairs($career->getIndustries(), 'industry_id', 'industry_name')], 'sections::portfolio-form');
$this->setPageTitle('Membership', 'Update portfolio item');
return $this->view->render('portfolio-edit', ['portfolio' => $portfolio->fetch()]);
}
示例6: __invoke
public function __invoke(Request $req, Response $res)
{
$identity = $this->authService->getIdentity();
if (null === $identity) {
return $res;
}
$user = R::load('user', $identity->id);
if (!$user->school_id) {
return $res;
}
$school_id = $user->school_id;
$sync = $this->syncFromInventory;
$result = $sync($school_id);
if (false === $result) {
return $res->withStatus(500);
}
return $res->withJson($result);
}
示例7: updateContent
public function updateContent(Request $request, Response $response, $arguments)
{
$data = $request->getParsedBody();
if (!$data) {
return $response->withJson(['message' => 'Could not parse JSON', 'errorCode' => 'JSON_PARSE_ERROR'], 400);
}
$content = Content::find($arguments['contentId']);
if (!$content) {
return $response->withJson(['message' => 'Content not found', 'errorCode' => 'CONTENT_NOT_FOUND'], 404);
}
$contentType = $this->container->ContentService->getContentTypeDefinition($content->content_type);
$fields = new \stdClass();
foreach ($contentType->fields as $currentField) {
if (array_key_exists($currentField->slug, $data)) {
$fields->{$currentField->slug} = $data[$currentField->slug];
}
}
$content->fields = $fields;
$content->save();
// TODO: return modified object
return $response->withJson($this->container->ContentService->convertFields($content, $contentType, $request), 201);
}
示例8: skillsCookie
public function skillsCookie(Request $request, Response $response, array $args)
{
$cookie = $request->getCookieParams();
if (!isset($cookie['skill-popup'])) {
setcookie('skill-popup', 1, $this->cookieTtl());
}
return $response->withJson(['resp' => 'OK']);
}
示例9: responseWithDenial
/**
* @param \Slim\Http\Request $request
* @param \Slim\Http\Response $response
* @return \Slim\Http\Response
*/
private function responseWithDenial(Request $request, Response $response)
{
$message = 'Permission denied, authorization required.';
// Response with json if XHR request
if ($request->isXhr()) {
return $response->withJson(['message' => $message], 401);
}
// Response with redirect if otherwise
$this->flash->addMessage('error', $message);
return $response->withRedirect($this->router->pathFor('membership-account'));
}
示例10: uploadMedia
public function uploadMedia(Request $request, Response $response, $arguments)
{
$errors = [];
foreach ($_FILES as $key => $file) {
$storage = new \Upload\Storage\FileSystem('uploads');
$file = new \Upload\File($key, $storage);
try {
$file->setName(s($file->getName())->slugify());
$file->upload();
} catch (\Exception $e) {
array_push($errors, 'Failed to upload ' . $file->getNameWithExtension());
}
}
return $response->withJson(['errors' => $errors], 200, JSON_PRETTY_PRINT);
}
示例11: json
/**
* Output JSON info about the video.
*
* @param Request $request PSR-7 request
* @param Response $response PSR-7 response
*
* @return Response HTTP response
*/
public function json(Request $request, Response $response)
{
$params = $request->getQueryParams();
if (isset($params['url'])) {
try {
$video = $this->download->getJSON($params['url']);
return $response->withJson($video);
} catch (\Exception $e) {
return $response->withJson(['success' => false, 'error' => $e->getMessage()]);
}
}
}
示例12: find
/**
* Find a user
*/
public function find(Request $request, Response $response, array $args)
{
return $response->withJson(UserModel::find($args["uid"]));
}
示例13: listApps
public function listApps(Request $request, Response $response, $arguments)
{
$apps = App::all();
return $response->withJson($apps, 200, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
}
示例14: remove
/**
* @param Request $request
* @param Response $response
* @param $args
*
* @return ResponseInterface
*/
public function remove(Request $request, Response $response, $args)
{
try {
$result = $this->gateway->delete($this->getIdArray($args));
return $response->withJson(["result" => $result]);
} catch (\Exception $e) {
return $response->withStatus(400);
}
}
示例15: deleteRelationsAction
/**
* Delete organizations relations action
*
* @param Request $request
* @param Response $response
* @param array $args
*
* @return Response
*/
public function deleteRelationsAction(Request $request, Response $response, $args)
{
$this->service->removeOrganizations();
return $response->withJson(null, 204);
}