问题描述
在解决了的部分问题之后,我意识到我可以把数据拿到视图中,但是我又遇到了一个问题。
After solving part of my problem over here, I realized that I could get the data into the view, but then I had another problem.
(控制器)
$this->load->model('testing/test_v_to_m_model');
$data['mydata'] = $this->test_v_to_m_model->display_character_info();
$this->load->view('testing/test_v_to_m_view', $data);
(型号)
$query = $this->doctrine->em->createQuery("select u from ORM\Dynasties2\Characters u");
return $query->getResult();
(查看)
foreach ($mydata as $key => $row) {
print_r($row);
}
这样返回输出:
所以...我只是不知道如何做任何事情 - 我尝试了一个嵌套foreach回显数据,不能让它工作。我希望它是因为这是一个对象,而不是一个数组是正确的?
And so... I just don't know how to do anything with this- I tried a nested foreach to echo data and couldn't get it to work. I expect that its because this is an Object, not an Array, is that correct?
-
我如何访问/操纵这些字段?
How exactly can I access/manipulate these fields?
是否有不同的代码,我可以在Doctrine2 / CodeIgniter2模型中使用会给数据更容易的字段名称 - 像相当于sql AS?
Is there different code that I can use in my Doctrine2/CodeIgniter2 model that will give the data easier field names - like the equivalent to sql AS?
推荐答案
p>您应该可以使用指针访问对象,如下所示:
You should be able to access the object with pointers, like so:
foreach ($mydata as $key => $row) {
echo($row->id);
echo($row->name);
}
是php的通用空类。这是一个很好的教程:
stdClass is php's generic empty class. Here is a nice tutorial on using this: http://krisjordan.com/dynamic-properties-in-php-with-stdclass
编辑:
尝试使用访问器:
echo($row->getId());
这篇关于结束对象,我该如何处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!