zf2 显示另一个模块中的模块动作 [英] zf2 display module action in another module

查看:20
本文介绍了zf2 显示另一个模块中的模块动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了两个模块第一个应用程序第二个评论.想法是在任何应用操作(网站页面)中使用评论模块(Widget).

Hi I created two modules first application second comment. Idea is to use comment module(Widget) in any application action (website page).

应用模块测试控制器

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'
    ));
}

使用简单的变量(列表)一切正常,

With simple variable (list) all working fine,

尝试将表单重定向回测试控制器中的评论操作时遇到的问题

Problem I get when trying to redirect form back to comment action in test controller

如果表单无效,我可以添加重定向到测试/评论但是我将如何将所有验证错误传递给测试/评论(表单)

I can add redirection to test/comment in case form is not valid but how I will pass all validating errors to test/comment(form)

你能告诉我,如果我在做的事情在逻辑上是正确的,或者在 ZF2 中我们有不同的方式来做小部件

Can you tell me, if what I'm doing logically correct or in ZF2 we have different way to do widgets

推荐答案

感谢帮助

来自weierophinney的回答

Answer from weierophinney

http://zend-framework-community.634137.n4.nabble.com/zf2-widget-base-app-logic-td4657457.html

这是我目前得到的:

https://github.com/nsenkevich/comment

这篇关于zf2 显示另一个模块中的模块动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆