我想用一个控制器控制其他一些具有自己模型的控制器(不是_forward)

发布于 2024-11-05 12:04:57 字数 1099 浏览 1 评论 0原文

我是 zend 框架的新手 这是我在互联网上问的第一个问题...抱歉我的英语不好! 我遇到了一个问题,几个小时后我就会跳出窗外;) 我有一个控制器 A,然后我需要 4 个其他控制器(B、C、D、E)来调用它们的模型并将答案提供给控制器 A。控制器 A 将其发送到视图。

遗憾的是,Zend_Framework 不允许这样的事情:

Class Arcticle_SteuerController {
    public function showAction() {
    .....
          $text = new Article_TextController();
          $opt = new Article_OptionController();
          $dates =  new Article_DatesController();

          $varText = $text->showTextAction();
          $varOpt = $opt->showOptAction();

          $this->view->varText;
          $this->view->varOpt;
            ....
    ....
    }
}

我在将所有内容放入一个控制器中时遇到了问题,因为每个控制器都有自己的模型,我认为这是错误的设计。 所以我想尝试从另一个类调用另一个函数。

我发现,并不是每个 Action 都需要一个视图...就像这样:

$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
$viewRenderer->setView($this->view)
             ->setNoController(true);
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);

问题是 _forward 仅在当前函数之后调用该函数。有人可以帮助我吗?有机会吗,还是我必须将所有内容都放在一个控制器中?

希望并感谢您的帮助

最好的问候汤姆

I'm new to zend framework and
its my first question I asked in the internet... sorry for my bad english!
I have got a problem and in some hours I would jump out of the window ;)
I have one controller A, then I need 4 other controllers (B, C,D,E) to call their models and give the answer to the controller A. Controller A send it after this to the view.

Zend_Framework sadly doesn't allow something like this:

Class Arcticle_SteuerController {
    public function showAction() {
    .....
          $text = new Article_TextController();
          $opt = new Article_OptionController();
          $dates =  new Article_DatesController();

          $varText = $text->showTextAction();
          $varOpt = $opt->showOptAction();

          $this->view->varText;
          $this->view->varOpt;
            ....
    ....
    }
}

I have got a problem to put everything in one Controller, because every Controller has its own model and this is wrong designing I think so.
So I want to try to call another function from another class.

I find something, that not every Action needs a view... like this:

$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
$viewRenderer->setView($this->view)
             ->setNoController(true);
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);

The problem is that _forward only call the function after the current function. Can anybody help me? Is there a chance, or do I have to put everything in one Controller?

Hope and thanks for help

Best regards Tom

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昇り龍 2024-11-12 12:04:57

ZF 并非设计为 HMVC 框架,但您可以实现这一点。一种方法可能是使用操作堆栈帮助器/插件。查看文档: http://framework.zend.com/manual/ en/zend.controller.actionhelpers.html

您应该能够从这些控制器的视图中获取 html。但是,我不确定如果整体使用此方法来模拟 HMVC,其可扩展性如何。

ZF isn't designed as an HMVC framework, but you can pull this off. One way might be by using an action stack helper/plugin. Check out the documentation: http://framework.zend.com/manual/en/zend.controller.actionhelpers.html

You should be able to get back html from those controllers' views. I'm not sure how scalable this method is if used overall to simulate an HMVC, however.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文