我有一个循环遍历返回狗信息的数据库表的视图。
这是控制器:
public function listAction()
{
$dogDao = new DogDao();
$this->view->infoDog = $dogDao->retrieveDogInfo();
}
在视图上,我可以像这样检索狗信息:
<?php for($i = 0; $i < 30; $i++){ ?>
if(isset($this->infoDog[$i])){
$dog = $this->infoDog[$i];
这工作正常。
我现在需要添加额外的狗特定信息,但是该狗信息不是我可以从“狗一般信息”表中获取的信息,它需要一些连接,并在最后检索一个数字。
public function retrieveVerySpecificInformation($dogId) {
return $numberSpecificForThatDog
};
我(相信)我需要一个助手来完成这些计算,我的问题是:
我应该在 for 所在的视图上调用这个助手,是吗?
但是我怎样才能以我为给定的狗 A 获得的方式连接这些信息,两者都是:
狗的一般信息和特定于该特定狗的数字 A ?
我的意思是,我们如何才能正确地将助手集成到这里?
我可以帮忙吗?
提前致谢,
MEM
I have a view that loops over a database table returning dogs information.
Here's the controller:
public function listAction()
{
$dogDao = new DogDao();
$this->view->infoDog = $dogDao->retrieveDogInfo();
}
On the view I can retrieve dog information like this:
<?php for($i = 0; $i < 30; $i++){ ?>
if(isset($this->infoDog[$i])){
$dog = $this->infoDog[$i];
This works fine.
I now need to add additional dog specific information but that dog information, is not an information that I can get from the Dog General Info table, it requires some joins, and the retrieval of a number at the end.
public function retrieveVerySpecificInformation($dogId) {
return $numberSpecificForThatDog
};
I (believe) I need a helper that does those calculations and my question is:
I should call this helper on the view where the for resides yes?
But how can I connect those informations in a way that I get for given dog A, both:
The general dog information AND that numberSpecific for that particular dog A ?
I mean, how can we properly integrate the helper here?
Can I have some help please?
Thanks in advance,
MEM
发布评论
评论(1)
您可以像这样调用视图助手,
并且您的视图助手应该像
这样OK从循环中调用视图助手进行几个数据库操作,但是当您为每只狗进行自定义数据库查询时()
建议
您应该在控制器中获取您需要的所有信息并将其传递到您的视图,稍后可以使用任何视图助手对其进行定制。
You may call view helper should like this
And your view helper should be like
It's OK call view helpers from a loop for couple of DB operations, BUT as you are making custom db query for each dog (30 queries are NOT RECOMMENDED)
Recommendation
You should fetch all info your need with in your controller and pass it to your views, which later can be costumed using any view helper.