如何从其他控制器获取部分页面
我的网站我有一些内容可以投票(+/-)。现在一切都运行良好,所有内容都有自己的投票者。 现在我正在寻找一种方法来创建带有实体(votedModel、votedId、用户、投票)的单个投票包。 基本上捆绑已经准备好了。我的问题是如何使用它。我希望能够执行以下操作:
class ... extends Controller {
function showAction(Request $request,$id) {
...
$voter=new Voter('myCOntentType',$id,$userid);
...
return $this->render('...', array('voter'=>$voter->getVoter(),...))
}
}
getVoter() 将创建选民视图。
但我不知道到底是如何开始的。我尝试以这种方式调用其他控制器,但无法创建投票者表单。
它与
$voter=$this->forward('VoterbundleNewAction', array('id=>$id,'user'=>$user)->getContent();<一起使用/code>
但这不是我想要的。
我认为我的方法是错误的 。我可能需要将其作为服务来完成,但我找不到办法。
My site I have some content can be voted (+/-). It is working fine now, when all content has its own voter.
Now I'm looking for a way to create a single voting bundle with a entity(votedModel,votedId, user, vote).
Basically the bundle is ready. My problem is how to use it. I'd like to be able to do something like:
class ... extends Controller {
function showAction(Request $request,$id) {
...
$voter=new Voter('myCOntentType',$id,$userid);
...
return $this->render('...', array('voter'=>$voter->getVoter(),...))
}
}
getVoter() would create the voter view.
but I'm stacked how exactly start. I tried to call for the other controller in this manner, but can't create the voter form.
It worked with
$voter=$this->forward('VoterbundleNewAction', array('id=>$id,'user'=>$user)->getContent();
But this wasn't I had in mind.
I think my approach is all wrong and I may need to do this as service. I cant find my way around.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在树枝模板中使用 include 或 render 来获取其他模板的输出。因此,您可以创建一个模板(例如,voter.html.twig),其中包含投票系统的 HTML,并且在 Twig 中,在任何需要投票者的地方,您可以使用:
或
在第一个示例中,您只需包含另一个模板(另请参阅:http://symfony.com/doc/current/book/templated.html#include-other-templates),在后一种情况下,您实际上执行控制器的另一个操作方法,并且其输出将放入您当前的模板中(另请参阅:http://symfony.com/doc/current/book/templatating.html#embedding-controllers)
You can use include or render in your twig template to get other templates' output. So you could create a template (say, voter.html.twig) that contains the HTML for your voting system, and in the Twig, in any place where you need a voter, you could use:
or
In the first example, you simply include another template (see also: http://symfony.com/doc/current/book/templating.html#including-other-templates), in the latter situation you actually execute another action method of a controller and the output of that is put into your current template (see also: http://symfony.com/doc/current/book/templating.html#embedding-controllers)