zend框架2在其他模块中加载模块

时间:2014-01-22 07:06:45

标签: php zend-framework2

我有两个名为'图像管理器'和'添加产品'的模块。我想在产品模块中的div中包含所有图像管理器视图。

有人请帮助我,

此致

兰卡

3 个答案:

答案 0 :(得分:1)

您可以使用forward()插件从另一个控制器操作中执行控制器操作,然后您可以将响应(ViewModel)添加为子视图。

这样做的主要好处是可以重复使用并保持为每个“视图”封装的控制器逻辑。这允许在不耦合/复制代码的情况下构建像视图一样的小部件。

例如

class ProductsController extends AbstractActionController
{
    public function viewProductAction()
    {
      //... View product controller logic
      //
      //

      $view = new ViewModel(array('foo', 'bar'));

      // Dispatch the controller to view images for this 'product_id'
      $viewManagerView = $this->forward()->dispatch('ImageManager\Controller\ViewImageController', array(
        'action'     => 'view-images',
        'product_id' => $product->getId(),
      ));
      // Attach the child view to the main view
      if ($viewManagerView instanceof ViewModel) {
        $view->addChild($viewManagerView, 'productImages');
      }

      return $view;
    }

}

然后在products-module/products/view-product.phtml内渲染子视图

echo $this->productImages;

您可以阅读有关转发插件in the documentation

的更多信息

答案 1 :(得分:0)

ViewHelper这种情况听起来很典型。虽然它也需要应用程序逻辑。你需要有一些方法将ProductsImages粘合在一起。

由于它是两个单独的模块,您可能会扩展ProductForm并在表单中注入一个新元素,以便用户可以选择他想要粘贴到产品的图像。这通常是1-N关系,因为一个产品可以有多个图像,但一个图像应该只属于一个产品。

如果你需要更多的帮助,那么你需要开始编码并回到真正的问题:)

答案 2 :(得分:0)

阅读你的评论,我发现它不是ZF2错误,甚至可能不是第三方模块,所以它可能是一个ElFinder错误。可能它找不到一些必要的资源。

阅读一些代码和一些webdites,我认为你可能只是缺少viewhelper的url选项,因此ElFinder可以找到他尝试连接的后端路由。

使用QuElFinder,连接器的路由为/quelfinder/connector  所以在你看来,代码将是:

echo $this->QuElFinder('elfinder', array(
    'width' => "50%",
    'height' => '300',
    'url' => '/quelfinder/connector'
    )
);

此外,您应该转到QuElFinder/config/module.config.php并检查

下的所有内容
 'QuConfig'=>array(
        'QuElFinder'=>array(

因为您可以在QuElFinder控制器中看到,在connectorAction()函数中,它正在读取该配置,并且有很多路径。

相关问题