数组未将 Properlyform 控制器渲染到树枝
array is not rendering Properlyform controller to twig
{{array.key}}
不打印值
这是我的 Twig 文件
<table>
<tr>
{% for count in 1..result|length %}
<td>
{% block tile %}
{% include 'tile.twig' %}
{% endblock %}
<h1>{{ result.id }}</h1>
</td>
{% if count is divisible by (6) %}
</tr>
<tr>
{% endif %}
{% endfor %}
</table>
这是我的控制器
public function fetchMyLiveAdIdsByUserId( Request $request, Response $response )
{
$args=$request->getParams();
$args=$args['id'];
$results = $this->m_objOlxUserDetails->fetchMyLiveAdIdsByUserId($args);
return $this->view->render($response,'profile.twig',['result' => $results]);
}
在{{result.id}}
处显示Nothing
以及 var_dump($results) 的输出;在控制器是*
array(3) {
[0]=> object(stdClass)#157 (1) {
["id"]=> int(1)
}
[1]=> object(stdClass)#185 (1) {
["id"]=> int(2)
}
[2]=> object(stdClass)#186 (1) {
["id"]=> int(4)
}
}
因为result
是对象数组,result.id
不存在,你应该使用
<h1>{{ result[count - 1].id }}</h1>
我减去 1
因为你的 count
从 1 开始,数组中的索引从 0 开始.
{{array.key}}
不打印值
这是我的 Twig 文件
<table>
<tr>
{% for count in 1..result|length %}
<td>
{% block tile %}
{% include 'tile.twig' %}
{% endblock %}
<h1>{{ result.id }}</h1>
</td>
{% if count is divisible by (6) %}
</tr>
<tr>
{% endif %}
{% endfor %}
</table>
这是我的控制器
public function fetchMyLiveAdIdsByUserId( Request $request, Response $response )
{
$args=$request->getParams();
$args=$args['id'];
$results = $this->m_objOlxUserDetails->fetchMyLiveAdIdsByUserId($args);
return $this->view->render($response,'profile.twig',['result' => $results]);
}
在{{result.id}}
以及 var_dump($results) 的输出;在控制器是*
array(3) {
[0]=> object(stdClass)#157 (1) {
["id"]=> int(1)
}
[1]=> object(stdClass)#185 (1) {
["id"]=> int(2)
}
[2]=> object(stdClass)#186 (1) {
["id"]=> int(4)
}
}
因为result
是对象数组,result.id
不存在,你应该使用
<h1>{{ result[count - 1].id }}</h1>
我减去 1
因为你的 count
从 1 开始,数组中的索引从 0 开始.