CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 6.0 API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 6.0
      • 6.0
      • 5.4
      • 5.3
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 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

  • Global
  • Cake
    • AttributeResolver
    • Cache
    • Collection
    • Command
    • Console
    • Container
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Lock
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Namespace View

Namespaces

  • Cake\View\Exception
  • Cake\View\Form
  • Cake\View\Helper
  • Cake\View\Widget

Function Detail

html() ΒΆ

html(string $html): Cake\View\HtmlString

Wrap trusted markup for rendering in HTML content positions without escaping it.

This function marks markup as trusted; it does not sanitize it.

Parameters
string $html

The trusted HTML.

Returns
Cake\View\HtmlString

Interfaces

  • HtmlStringable

    Marks trusted markup that can be rendered verbatim in HTML content positions.

    Implementations must escape any untrusted values included in their markup. This contract does not bypass attribute escaping or explicit calls to h().

Classes

  • AjaxView

    A view class that is used for AJAX responses. Currently, only switches the default layout and sets the response type - which just maps to text/html by default.

  • Cell

    Cell base.

  • Helper

    Abstract base class for all other Helpers in CakePHP. Provides common methods and features.

    Callback methods

    Helpers support a number of callback methods. These callbacks allow you to hook into the various view lifecycle events and either modify existing view content or perform other application specific logic. The events are not implemented by this base class, as implementing a callback method subscribes a helper to the related event. The callback methods are as follows:

    • beforeRender(EventInterface $event, $viewFile) - beforeRender is called before the view file is rendered.
    • afterRender(EventInterface $event, $viewFile) - afterRender is called after the view file is rendered but before the layout has been rendered.
    • beforeLayout(EventInterface $event, $layoutFile)` - beforeLayout is called before the layout is rendered.
    • afterLayout(EventInterface $event, $layoutFile) - afterLayout is called after the layout has rendered.
    • beforeRenderFile(EventInterface $event, $viewFile) - Called before any view fragment is rendered.
    • afterRenderFile(EventInterface $event, $viewFile, $content) - Called after any view fragment is rendered. If a listener returns a non-null value, the output of the rendered file will be set to that.
  • HelperRegistry

    HelperRegistry is used as a registry for loaded helpers and handles loading and constructing helper class objects.

  • HtmlString

    An immutable value containing developer-controlled HTML.

    This class marks markup as trusted; it does not sanitize it.

  • JsonView

    A view class that is used for JSON responses.

    It allows you to omit templates if you just need to emit JSON string as response.

    In your controller, you could do the following:

    $this->set(['posts' => $posts]);
    $this->viewBuilder()->setOption('serialize', true);

    When the view is rendered, the $posts view variable will be serialized into JSON.

    You can also set multiple view variables for serialization. This will create a top level object containing all the named view variables:

    $this->set(compact('posts', 'users', 'stuff'));
    $this->viewBuilder()->setOption('serialize', true);

    The above would generate a JSON object that looks like:

    {"posts": [...], "users": [...]}

    You can also set 'serialize' to a string or array to serialize only the specified view variables.

    If you don't set the serialize option, you will need a view template. You can use extended views to provide layout-like functionality.

    You can also enable JSONP support by setting jsonp option to true or a string to specify custom query string parameter name which will contain the callback function name.

  • NegotiationRequiredView

    A view class that responds to any content-type and can be used to create an empty body 406 status code response.

    This is most useful when using content-type negotiation via viewClasses() in your controller. Add this View at the end of the acceptable View classes to require clients to pick an available content-type and that you have no default type.

  • SerializedView

    Parent class for view classes generating serialized outputs like JsonView and XmlView.

  • StringTemplate

    Provides an interface for registering and inserting content into simple logic-less string templates.

    Used by several helpers to provide simple flexible templates for generating HTML and other content.

  • View

    View, the V in the MVC triad. View interacts with Helpers and view variables passed in from the controller to render the results of the controller action. Often this is HTML, but can also take the form of JSON, XML, PDF's or streaming files.

    CakePHP uses a two-step-view pattern. This means that the template content is rendered first, and then inserted into the selected layout. This also means you can pass data from the template to the layout using $this->set()

    View class supports using plugins as themes. You can set

    public function beforeRender(\Cake\Event\EventInterface $event)
    {
         $this->viewBuilder()->setTheme('SuperHot');
    }

    in your Controller to use plugin SuperHot as a theme. Eg. If current action is PostsController::index() then View class will look for template file plugins/SuperHot/templates/Posts/index.php. If a theme template is not found for the current action the default app template file is used.

  • ViewBlock

    ViewBlock implements the concept of Blocks or Slots in the View layer. Slots or blocks are combined with extending views and layouts to afford slots of content that are present in a layout or parent view, but are defined by the child view or elements used in the view.

  • ViewBuilder

    Provides an API for iteratively building a view up.

    Once you have configured the view and established all the context you can create a view instance with build().

  • XmlView

    A view class that is used for creating XML responses.

    By setting the 'serialize' option in view builder of your controller, you can specify a view variable that should be serialized to XML and used as the response for the request. This allows you to omit views and layouts, if you just need to emit a single view variable as the XML response.

    In your controller, you could do the following:

    $this->set(['posts' => $posts]);
    $this->viewBuilder()->setOption('serialize', true);

    When the view is rendered, the $posts view variable will be serialized into XML.

    Note The view variable you specify must be compatible with Xml::fromArray().

    You can also set 'serialize' as an array. This will create an additional top level element named <response> containing all the named view variables:

    $this->set(compact('posts', 'users', 'stuff'));
    $this->viewBuilder()->setOption('serialize', true);

    The above would generate an XML object that looks like:

    <response><posts>...</posts><users>...</users></response>

    You can also set 'serialize' to a string or array to serialize only the specified view variables.

    If you don't set the serialize option, you will need a view. You can use extended views to provide layout like functionality.

Traits

  • CellTrait

    Provides cell() method for usage in Controller and View classes.

  • StringTemplateTrait

    Adds string template functionality to any class by providing methods to load and parse string templates.

    This trait requires the implementing class to provide a config() method for reading/updating templates. An implementation of this method is provided by Cake\Core\InstanceConfigTrait

  • ViewVarsTrait

    Provides the set() method for collecting template context.

    Once collected context data can be passed to another object. This is done in Controller, TemplateTask and View for example.

OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs