phalcon

编程入门 行业动态 更新时间:2024-10-28 04:30:32
本文介绍了phalcon-如何循环通过关联(数组)模型:: find();输出键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想遍历model :: find结果的列. 我认为可能的是将返回的对象强制转换为数组,以便能够遍历各列,但这是行不通的.

I want to loop through the columns of the model::find results. What I thought was possible is to cast the returning object to an array to be able to loop throught the columns, but that does not work.

这是我的 控制器代码:

Here is my Controller code:

<?php class ManageController extends ControllerBase { public function indexAction() { $this->view->setVar("pages",(array) Pages::find()); } }

并查看代码:

{% for key,value in pages %} <p>key: {{key}}</p> {% endfor%}

任何帮助都是有用的

推荐答案

使用它;

<?php class ManageController extends ControllerBase { public function indexAction() { $this->view->setVar("pages", Pages::find()); } }

并查看代码:

{% for page in pages %} {# in this case the key is just "0,1,2,3..." #} {# so we use the loop index (or loop.index0 for zero based) #} <p>This is the page #{{ loop.index }}</p> <p>{{ page.title }}</p> {% endfor%}

但是,如果您确实还需要遍历各个键,请使用:

But if you really need to loop through the keys too, use:

{% for key, value in items %} Key: {{ key }} Value: {{ value }} {% endfor%}

更多推荐

phalcon

本文发布于:2023-10-28 22:37:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537972.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:phalcon

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!