如何将 Zend Framework 的部分循环与对象一起使用
我很困惑如何使用 partialLoop
目前我使用
foreach ($childrenTodos as $childTodo) {
echo $this->partial('todos/_row.phtml', array('todo' => $childTodo));
}
$childrenTodos
是一个 Doctrine\ORM\PersistantCollection
,$childTodo
> 是一个 Application\Models\Todo
我尝试做
echo $this->partialLoop('todos/_row.phtml', $childrenTodos)
->setObjectKey('Application\Models\Todo');
但是在部分中,当我尝试访问我的 Todo 类的属性/函数时,我似乎无法让它们总是以调用未定义的方法而结束Zend_View::myFunction()
当我在部分中使用 $this->myFunction()
时或者如果我尝试 $this->todo->; getName()
我得到“调用非对象上的成员函数 getName()”。如何使用partialLoops?
I am quite confused how to use partialLoop
Currently I use
foreach ($childrenTodos as $childTodo) {
echo $this->partial('todos/_row.phtml', array('todo' => $childTodo));
}
$childrenTodos
is a Doctrine\ORM\PersistantCollection
, $childTodo
is a Application\Models\Todo
I tried doing
echo $this->partialLoop('todos/_row.phtml', $childrenTodos)
->setObjectKey('Application\Models\Todo');
But in the partial when I try to access properties/functions of my Todo class, I cant seem to get them always ending up with either call to undefined method Zend_View::myFunction()
when I use $this->myFunction()
in the partial or if I try $this->todo->getName()
I get "Call to a member function getName() on a non-object". How do I use partialLoops?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个
然后在你的部分中你可以访问对象,就像这样
object
是将对象分配给的变量的名称如果你有的话,你也可以在你的 Bootstrap 或其他初始化类中执行此操作一次像这样访问视图对象
Try this
Then in your partial you can access the object like this
object
is the name of the variable that an object will be assigned toYou can also do this once in your Bootstrap or other initialization class if you have access to the view object like so
在尝试建议的语法时,我也遇到了“调用非对象上的函数”错误,似乎他们在更高版本的 Zend Framework 上更改了某些内容。以下内容对我在 ZF1.12 上有效:
I also had "Call to function on non object" error when trying suggested syntax, seems like they've changed something on later versions of Zend Framework. The following works for me on ZF1.12: