Как передать переменную в Zend 3 Fieldset? - PullRequest
0 голосов
/ 28 июня 2018

Как передать переменную в Zend 3 Fieldset?

У меня есть раскрывающийся список, который я заполняю с использованием таблицы базы данных, однако мне нужен идентификатор продукта из запроса на получение, чтобы показать только опции, доступные для этого продукта?

1 Ответ

0 голосов
/ 29 июня 2018

Я решил это, запросив объект 'router' и 'request' у фабрики fildset, чтобы получить параметр из URL, а затем передал его в набор файлов. Вот код:

namespace Catalog\Form\Factory;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;
use Catalog\Form\ProductBrandingOptionPricesFieldset;

class ProductBrandingOptionPricesFieldsetFactory implements FactoryInterface
{    
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
        $entityManager = $container->get('doctrine.entitymanager.orm_default');
        
        $router = $container->get('router');
        $request = $container->get('request');
        
        // Get the router match
        $productId = $router->match($request)->getParam("id");

        // Instantiate the controller and inject dependencies
        return new ProductBrandingOptionPricesFieldset($entityManager,$productId);
    }

}
...