我在我的 Laminas 项目中遇到了一个问题。在我的控制器中,我用参数调用了我的表单。我的表单包含字段集的添加功能,我想读取我的字段集中的参数。我怎样才能做到这一点 ?
这是我的控制器中的功能:
public function realisationImpactAction(){
$post=$this->post;
$mapperProjet = $this->SM->get('TPROJET');
$mapperDoc = $this->SM->get('TDOC');
//$hydrator = new ArraySerializableHydrator();
//$reflectionHydrator = new \Laminas\Hydrator\ReflectionHydrator();
$supervision = new Supervision();
$id = (int) $this->params()->fromRoute('id');
if (0 === $id) {
return $this->redirect()->toRoute('front-supervision',['action' => 'edition-projet','id' => $id]);
}
$projet = $mapperProjet->fetchRow(['idProjet' => $id]);
$docs = $mapperDoc->getDocsByProjetId($id);
$realisationImpactForm = $this->formManager->get(RealisationImpactForm::class,['idProjet' => $id,'idSupervision' => 1]);
//$realisationImpactForm->bind($supervision)->setInputFilter($supervision->getInputFilter())->setData($post);
if(!$post){
return new ViewModel(['form' => $realisationImpactForm,'user' => $this->user,'id' => $id,'projet' => $projet,'docs' => $docs]);
}
}
这是我的表格:
<?php
/**
* @module Commun
* @subpackage Form\Admin
* @author Samuel NANGUI <nanguisamuel@gmail.com>
* @copyright Copyright (c) 2021 Nslabs
*/
namespace Commun\Form\Modules\Application;
use Commun\Form\Modules\Application\Fieldset\RealisationImpactFieldset;
use Commun\Form\CommunForm;
class RealisationImpactForm extends CommunForm
{
/*private $params;
public function __construct($params) {
$this->params = $params;
parent::__construct('RealisationImpactForm',$this->params);
}*/
public function init() {
//var_dump($this); // this shows correcty my params values
$this->setName('RealisationImpactForm');
$this->addFieldset(RealisationImpactFieldset::class,['use_as_base_fieldset' => true,'params' => $this->params]);
$this->addSubmitButton('next', 'Poursuivre', 'next', 'btn btn-vert w-100');
$this->addSubmitButton('previous', 'Retour', 'previous', 'btn btn-rouge w-100');
}
}
这是我的字段集
<?php
/**
* @module Commun
* @subpackage Form\Admin
* @author Samuel NANGUI <nanguisamuel@gmail.com>
* @copyright Copyright (c) 2020 Nslabs
*/
namespace Commun\Form\Modules\Application\Fieldset;
use Commun\Model\Entity\Supervision;
use Laminas\InputFilter\InputFilterProviderInterface;
use Laminas\Hydrator\ReflectionHydrator;
use Commun\Form\CommunFormFieldset;
class RealisationImpactFieldset extends CommunFormFieldset implements InputFilterProviderInterface
{
private $mapper;
/*private $idProjet;
private $idSupervision;*/
public function __construct($mappers=[],$options=[])
{
$this->mapper = $mappers;
/*$this->idProjet = $idProjet;
$this->idSupervision = $idSupervision;*/
parent::__construct('RealisationImpactForm',$options);
$this->setHydrator(new ReflectionHydrator());
$this->setObject(new Supervision());
$this->setLabel('Realisation Impact');
}
public function init() {
parent::init();
//$effets = $this->mapper['supervision']->getRapportEffetByProjetForSuivi($this->idProjet,$this->idSupervision);
/*$this->addText('libelle','Intitulé de l\'activité','libelle',['class' => 'form-control champ-requis']);
$options = $this->mapper['indicateur']->getOptions('idRefIndicateur','libelle','Aucune valeur choisie',null,['libelle']);
$this->addSelect('idRefIndicateur','Indicateur de performance',$options,['class' => 'form-control']);
$this->addText('valeurReference','Valeur de référence','valeurReference',['class' => 'form-control champ_decimal']);
$this->addText('valeurCible','Valeur cible','valeurCible',['class' => 'form-control champ_decimal']);
$this->addTextarea('moyenVerification', 'Moyen de vérification', 'moyenVerification', ['class' => 'form-control','rows' => 3]);
$this->addTextarea('risqueMesureAttenuation', 'Risques et mesures d\'atténuation', 'risqueMesureAttenuation', ['class' => 'form-control','rows' => 3]); */
}
/**
* @return array
*/
public function getInputFilterSpecification()
{
return [
];
}
}
问题是如何将我的参数放入字段集 __construct 或 init 函数中?