2
嗨我创建了两个模块的第一个应用程序的第二个评论。 想法是在任何应用程序操作(网站页面)中使用注释模块(Widget)。zf2显示模块在另一个模块中的动作
应用模块 测试控制器
public function commentAction(){
//seting redirection for form
$this->getCommentService()->setRedirection('test/comment');
$list = $this->forward()->dispatch('comment_controrller', array('action' => 'list'));
$add = $this->forward()->dispatch('comment_controrller', array('action' => 'add'));
$view = new ViewModel();
$view->addChild($list, 'list');
$view->addChild($add, 'add');
return $view;
}
查看
评论模块 评论控制器
public function addAction()
{
$form = new CommentForm();
$form->get('submit')->setAttribute('value', 'Add');
$request = $this->getRequest();
if ($request->isPost()) {
$comment = new Comment();
$form->setInputFilter($comment ->getInputFilter());
$form->setData($request->getPost());
if ($form->isValid()) {
$comment ->exchangeArray($form->getData());
$this->getCommentTable()->saveComment($comment);
// Redirect to test controller in application module
return $this->redirect()->toRoute($this->getCommentService()->getRedirection());
}
}
return array('form' => $form);
}
public function listAction()
{
return new ViewModel(array(
$list=> 'test'
));
}
通过简单的变量(列表)的所有工作正常,
问题我在尝试时重定向形式回评动作测试控制器
我可以添加重定向测试/万一格式的注释是无效 但如何我会通过所有验证错误测试/评论(形式)
你能告诉我,如果我在做什么逻辑正确或ZF2我们有不同的方式做小部件
我认为这篇文章可以帮助你:http://www.michaelgallego.fr/blog/?p=223 – AlloVince