JsonViewHelper
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'})}
{f:format.json(value: {0: 'bar', 1: 'baz'}, forceObject: true)}
<output>
{"0":"bar","1":"baz"}
</output>
Properties
protected ControllerContext | $controllerContext | Controller Context to use |
from AbstractViewHelper |
protected ObjectManagerInterface | $objectManager | from AbstractViewHelper | |
protected LoggerInterface | $logger | from AbstractViewHelper | |
protected bool | $escapeChildren |
Methods
No description
Injects the (system) logger based on PSR-3.
Register a new argument. Call this method from your ViewHelper subclass inside the initializeArguments() method.
Overrides a registered argument. Call this method from your ViewHelper subclass inside the initializeArguments() method if you want to override a previously registered argument.
Initialize the arguments.
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.
No description
Details
void
setRenderingContext(RenderingContextInterface $renderingContext)
No description
void
injectObjectManager(ObjectManagerInterface $objectManager)
No description
void
injectLogger(LoggerInterface $logger)
Injects the (system) logger based on PSR-3.
protected AbstractViewHelper
registerArgument(string $name, string $type, string $description, bool $required = false, mixed $defaultValue = null, bool|null $escape = null)
Register a new argument. Call this method from your ViewHelper subclass inside the initializeArguments() method.
This exists only to throw our own exception!
protected AbstractViewHelper
overrideArgument(string $name, string $type, string $description, bool $required = false, mixed $defaultValue = null, bool|null $escape = null)
Overrides a registered argument. Call this method from your ViewHelper subclass inside the initializeArguments() method if you want to override a previously registered argument.
This exists only to throw our own exception!
bool
isEscapingInterceptorEnabled()
No description
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.
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"}
string
compile(string $argumentsName, string $closureName, string $initializationPhpCode, ViewHelperNode $node, TemplateCompiler $compiler)
No description