CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.7 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.7
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • AjaxView
  • Cell
  • Helper
  • HelperRegistry
  • JsonView
  • SerializedView
  • StringTemplate
  • View
  • ViewBlock
  • ViewBuilder
  • XmlView

Traits

  • CellTrait
  • StringTemplateTrait
  • ViewVarsTrait
  1: <?php
  2: /**
  3:  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4:  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5:  *
  6:  * Licensed under The MIT License
  7:  * For full copyright and license information, please see the LICENSE.txt
  8:  * Redistributions of files must retain the above copyright notice.
  9:  *
 10:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 11:  * @link          https://cakephp.org CakePHP(tm) Project
 12:  * @since         3.1.0
 13:  * @license       https://opensource.org/licenses/mit-license.php MIT License
 14:  */
 15: namespace Cake\View;
 16: 
 17: use Cake\Event\EventManager;
 18: use Cake\Http\Response;
 19: use Cake\Http\ServerRequest;
 20: use RuntimeException;
 21: 
 22: /**
 23:  * Parent class for view classes generating serialized outputs like JsonView and XmlView.
 24:  */
 25: abstract class SerializedView extends View
 26: {
 27: 
 28:     /**
 29:      * Response type.
 30:      *
 31:      * @var string
 32:      */
 33:     protected $_responseType;
 34: 
 35:     /**
 36:      * Constructor
 37:      *
 38:      * @param \Cake\Http\ServerRequest|null $request Request instance.
 39:      * @param \Cake\Http\Response|null $response Response instance.
 40:      * @param \Cake\Event\EventManager|null $eventManager EventManager instance.
 41:      * @param array $viewOptions An array of view options
 42:      */
 43:     public function __construct(
 44:         ServerRequest $request = null,
 45:         Response $response = null,
 46:         EventManager $eventManager = null,
 47:         array $viewOptions = []
 48:     ) {
 49:         if ($response && $response instanceof Response) {
 50:             $response = $response->withType($this->_responseType);
 51:         }
 52:         parent::__construct($request, $response, $eventManager, $viewOptions);
 53:     }
 54: 
 55:     /**
 56:      * Load helpers only if serialization is disabled.
 57:      *
 58:      * @return void
 59:      */
 60:     public function loadHelpers()
 61:     {
 62:         if (empty($this->viewVars['_serialize'])) {
 63:             parent::loadHelpers();
 64:         }
 65:     }
 66: 
 67:     /**
 68:      * Serialize view vars.
 69:      *
 70:      * @param array|string $serialize The name(s) of the view variable(s) that
 71:      *   need(s) to be serialized
 72:      * @return string The serialized data
 73:      */
 74:     abstract protected function _serialize($serialize);
 75: 
 76:     /**
 77:      * Render view template or return serialized data.
 78:      *
 79:      * ### Special parameters
 80:      * `_serialize` To convert a set of view variables into a serialized form.
 81:      *   Its value can be a string for single variable name or array for multiple
 82:      *   names. If true all view variables will be serialized. If unset normal
 83:      *   view template will be rendered.
 84:      *
 85:      * @param string|bool|null $view The view being rendered.
 86:      * @param string|null $layout The layout being rendered.
 87:      * @return string|null The rendered view.
 88:      */
 89:     public function render($view = null, $layout = null)
 90:     {
 91:         $serialize = false;
 92:         if (isset($this->viewVars['_serialize'])) {
 93:             $serialize = $this->viewVars['_serialize'];
 94:         }
 95: 
 96:         if ($serialize !== false) {
 97:             $result = $this->_serialize($serialize);
 98:             if ($result === false) {
 99:                 throw new RuntimeException('Serialization of View data failed.');
100:             }
101: 
102:             return (string)$result;
103:         }
104:         if ($view !== false && $this->_getViewFileName($view)) {
105:             return parent::render($view, false);
106:         }
107:     }
108: }
109: 
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs