pandukhabaya
pandukhabaya

Reputation: 13

zend framework 2 loading modules in other module

I have two modules called 'image manager' and 'add products'. I want to include all image manager view inside a div in products module .

someone please help me,

Regards,

Lanka

Upvotes: 1

Views: 202

Answers (3)

Carlos Robles
Carlos Robles

Reputation: 10947

Reading your comments, i see that it is not a ZF2 error, and probably not even a third party module, so it could be an ElFinder Error. Probably it cannot find some required resources.

Reading some code and some webdites, i think that probably you are just lacking the url option of the viewhelper, so ElFinder can find the backend route he tries to connect to.

With the QuElFinder, the route to the connector is /quelfinder/connector so in your view, the code will be:

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

Also, you should go to QuElFinder/config/module.config.php and check everything under

 'QuConfig'=>array(
        'QuElFinder'=>array(

because as you can see in the QuElFinder controller, in the connectorAction() function, it is reading that configuration, and there is a lot of paths.

Upvotes: 0

AlexP
AlexP

Reputation: 9857

You can execute a controller action from within another controller action using the forward() plugin, where you can then add the response (ViewModel) as a child view.

The main benefit of this is that you reuse and keep the controller logic encapsulated for each 'view'. This allows the build up a widget like views without coupling/duplicating code.

For example

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

}

An then within a products-module/products/view-product.phtml render the child view

echo $this->productImages;

You can read more about the forward plugin in the documentation

Upvotes: 1

Sam
Sam

Reputation: 16455

This kind of scenario sounds typical for a ViewHelper. Though it requires application logic, too. You'd need to have some way of gluing Products and Images together.

Since it's two separate Modules you'd probably extend the ProductForm and inject a new Element into the Form so that the User could choose the images he want to glue to the Product. This would usually be a 1-N Relationship since one Product can have many Images but one Image should only belong to one Product.

If you need more help than that, then you need to start coding and come back with real questions :)

Upvotes: 0

Related Questions