Php Phalcon在Volt View中访问动态变量
我目前正在为一个项目学习phalcon和volt。有人知道如何动态访问视图页面中的变量吗 例如,我的控制器中有这个Php Phalcon在Volt View中访问动态变量,php,phalcon,volt,Php,Phalcon,Volt,我目前正在为一个项目学习phalcon和volt。有人知道如何动态访问视图页面中的变量吗 例如,我的控制器中有这个 $arr = array('a','b','c','d'); foreach($arr as $name) { $this->view->$name = constant($name); } $this->view->arr = $arr; $this->view->$name,我想在volt视图中获取分配给$name的值 在我看来 {% for
$arr = array('a','b','c','d');
foreach($arr as $name)
{
$this->view->$name = constant($name);
}
$this->view->arr = $arr;
$this->view->$name,我想在volt视图中获取分配给$name的值
在我看来
{% for name in arr%}
<div>
<label>{{ name }}</label>
<span>{{ name }}</span>
</div>
{% endfor %}
{%表示arr%中的名称]
{{name}}
{{name}}
{%endfor%}
它同时显示“a”,但我需要的是,如果$a='Test',它应该在标签中显示“a”,在值中显示“Test”。直接来自:
因此,在您的情况下,它将类似于:
{% for key,value in arr if key == 'a' and value == 'Test'%}
<div>
<label>{{ key }}</label>
<span>{{ value }}</span>
</div>
{% endfor %}
{%对于键,如果键='a'和值='Test%}
{{key}}
{{value}}
{%endfor%}
但在您的示例中,您永远不会得到$a='Test',因为在$arr中将'a'替换为'Test'将直接导致$Test='Test'而不是$a='Test':
因此,在您的情况下,它将类似于:
{% for key,value in arr if key == 'a' and value == 'Test'%}
<div>
<label>{{ key }}</label>
<span>{{ value }}</span>
</div>
{% endfor %}
{%对于键,如果键='a'和值='Test%}
{{key}}
{{value}}
{%endfor%}
但是,在您的示例中,您永远不会得到$a='Test',因为在$arr中用'Test'替换'a'将导致$Test='Test'而不是$a='Test'您永远不会得到$a='Test',因为在$arr中用'Test'替换'a'将导致$Test='Test'而不是$a='Test',您永远不会得到$a='Test',因为在$arr中用'Test'替换'a'将导致$Test='Test'而不是$a='Test'