class JsonViewHelper extends AbstractViewHelper (View source)

Wrapper for PHPs json_encode function.

= Examples =

{someArray -> f:format.json()}

<output>
["array","values"]
// depending on the value of {someArray}
</output>

<code title="associative array">
{f:format.json(value: {foo: 'bar', bar: 'baz'})}
{"foo":"bar","bar":"baz"}

{f:format.json(value: {0: 'bar', 1: 'baz'}, forceObject: true)}


<output>
{"0":"bar","1":"baz"}
</output>

Properties

protected RenderingContextInterface $renderingContext from  AbstractViewHelper
protected ControllerContext $controllerContext

Controller Context to use

from  AbstractViewHelper
protected ObjectManagerInterface $objectManager from  AbstractViewHelper
protected LoggerInterface $logger from  AbstractViewHelper
protected bool $escapeChildren

Methods

void
setRenderingContext(RenderingContextInterface $renderingContext)

No description

void
injectObjectManager(ObjectManagerInterface $objectManager)

No description

void
injectLogger(LoggerInterface $logger)

Injects the (system) logger based on PSR-3.

void
initializeArguments()

Initialize the arguments.

string
render()

Outputs content with its JSON representation. To prevent issues in HTML context, occurrences of greater-than or less-than characters are converted to their hexadecimal representations.

string
compile(string $argumentsName, string $closureName, string $initializationPhpCode, ViewHelperNode $node, TemplateCompiler $compiler)

No description

Details

void setRenderingContext(RenderingContextInterface $renderingContext)

No description

Parameters

RenderingContextInterface $renderingContext

Return Value

void

void injectObjectManager(ObjectManagerInterface $objectManager)

No description

Parameters

ObjectManagerInterface $objectManager

Return Value

void

void injectLogger(LoggerInterface $logger)

Injects the (system) logger based on PSR-3.

Parameters

LoggerInterface $logger

Return Value

void

bool isEscapingInterceptorEnabled()

No description

Return Value

bool

void initializeArguments()

Initialize the arguments.

Return Value

void

string render()

Outputs content with its JSON representation. To prevent issues in HTML context, occurrences of greater-than or less-than characters are converted to their hexadecimal representations.

If $forceObject is true a JSON object is outputted even if the value is a non-associative array Example: array('foo', 'bar') as input will not be ["foo","bar"] but {"0":"foo","1":"bar"}

Return Value

string

the JSON-encoded string.

See also

http://www.php.net/manual/en/function.json-encode.php

string compile(string $argumentsName, string $closureName, string $initializationPhpCode, ViewHelperNode $node, TemplateCompiler $compiler)

No description

Parameters

string $argumentsName
string $closureName
string $initializationPhpCode
ViewHelperNode $node
TemplateCompiler $compiler

Return Value

string