I have a view class with a function to create a view
class view {
public function build() {
$view = $this;
$data = $this->resources->data;
function s($value) {
return \classes\tools\html\html::specialChars($value);
}
require $this->viewFile;
}
}
And viewing some view files
<?php var_dump($view);
<?= s($data->someUnsafeString) ?>
<?php
I could define a function sin each view file, but I really don't want to do this.
I could pass the function as a variable $s=function(){..}, but I would prefer not too
I could call the static function in the view directly, but even longer than I would like:
<?= html::s($data->someUnsafeString) ?>
Is it possible? or any other suggestions?
source
share