Namespaces

  • Nette
    • Application
    • Caching
    • Collections
    • Config
    • Forms
    • IO
    • Loaders
    • Mail
    • Reflection
    • Security
    • Templates
    • Web
  • None
  • PHP

Classes

  • AppForm
  • Application
  • CliRouter
  • Control
  • DownloadResponse
  • ForwardingResponse
  • JsonResponse
  • Link
  • MultiRouter
  • Presenter
  • PresenterComponent
  • PresenterLoader
  • PresenterRequest
  • RedirectingResponse
  • RenderResponse
  • Route
  • SimpleRouter

Interfaces

  • IPartiallyRenderable
  • IPresenter
  • IPresenterLoader
  • IPresenterResponse
  • IRenderable
  • IRouter
  • ISignalReceiver
  • IStatePersistent

Exceptions

  • AbortException
  • ApplicationException
  • BadRequestException
  • BadSignalException
  • ForbiddenRequestException
  • InvalidLinkException
  • InvalidPresenterException
  • Overview
  • Namespace
  • Class
  • Tree
  • Other releases
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (https://nette.org)
 5:  *
 6:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
 7:  *
 8:  * For the full copyright and license information, please view
 9:  * the file license.txt that was distributed with this source code.
10:  */
11: 
12: namespace Nette\Application;
13: 
14: use Nette;
15: 
16: 
17: 
18: /**
19:  * JSON response used for AJAX requests.
20:  *
21:  * @author     David Grudl
22:  */
23: class JsonResponse extends Nette\Object implements IPresenterResponse
24: {
25:     /** @var array|stdClass */
26:     private $payload;
27: 
28:     /** @var string */
29:     private $contentType;
30: 
31: 
32: 
33:     /**
34:      * @param  array|stdClass  payload
35:      * @param  string    MIME content type
36:      */
37:     public function __construct($payload, $contentType = NULL)
38:     {
39:         if (!is_array($payload) && !($payload instanceof \stdClass)) {
40:             throw new \InvalidArgumentException("Payload must be array or anonymous class, " . gettype($payload) . " given.");
41:         }
42:         $this->payload = $payload;
43:         $this->contentType = $contentType ? $contentType : 'application/json';
44:     }
45: 
46: 
47: 
48:     /**
49:      * @return array|stdClass
50:      */
51:     final public function getPayload()
52:     {
53:         return $this->payload;
54:     }
55: 
56: 
57: 
58:     /**
59:      * Sends response to output.
60:      * @return void
61:      */
62:     public function send()
63:     {
64:         Nette\Environment::getHttpResponse()->setContentType($this->contentType);
65:         Nette\Environment::getHttpResponse()->setExpiration(FALSE);
66:         echo json_encode($this->payload);
67:     }
68: 
69: }
70: 
Nette Framework 0.9.7 API documentation generated by ApiGen 2.3.0