【发布时间】:2017-01-23 02:39:10
【问题描述】:
我目前正在为一个项目研究 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 name in arr%}
<div>
<label>{{ name }}</label>
<span>{{ name }}</span>
</div>
{% endfor %}
它同时显示“a”,但我需要的是如果 $a = 'Test'它应该在标签中显示“a”,在值中显示“Test”。
【问题讨论】:
-
你永远不会得到 $a = 'Test' 因为在 $arr 中用 'Test' 替换 'a' 会导致 $Test='Test' 而不是 $a='Test'跨度>