如何在Helper中访问CakePHP 3中为视图设置的变量?我没有在文档中找到任何内容。
在CakePHP 2.x中,这曾经起作用:
$this->_View->viewVars['foo'];
答案 0 :(得分:3)
655: /**
656: * Returns the contents of the given View variable.
657: *
658: * @param string $var The view var you want the contents of.
659: * @param mixed $default The default/fallback content of $var.
660: * @return mixed The content of the named var if its set, otherwise $default.
661: */
662: public function get($var, $default = null)
663: {
664: if (!isset($this->viewVars[$var])) {
665: return $default;
666: }
667:
668: return $this->viewVars[$var];
669: }