좋아, 나는 도움을 주셔서 감사합니다. 도와 주셔서 감사합니다. :-)
다른 사람이 이러한 문제에 직면 들어, I는 다음과 같이하여 해결 :
폼 요소 (크기 Atribute가 렌더링되는 라디오 버튼 표 제목의 양이다).
<?php
/**
* @namespace
*/
namespace ExecuteSurvey\Form\Element;
/**
* @uses Zend\Form\Element
*/
use Zend\Form\Element;
/**
* Custom Form Element that is here for rendering a Matrix of Radio Elements
* @category ExecuteSurvey
* @package ExecuteSurvey_Form
* @subpackage ExecuteSurvey_Form_Element
* @author Dominik Einkemmer
*/
class RadioMatrix extends Element {
protected $attribute = array(
'type' => 'radiomatrix'
);
private $labels = array();
private $size;
public function setSize($size){
if($size == 0 || !is_numeric($size)){
throw new Exception("Size can't be 0 and has to be numeric");
}
$this->size = $size;
}
public function setLabels(array $labels){
if(!is_array($labels)){
throw new \Zend\Form\Exception\InvalidArgumentException("Array expected but ".gettype($labels)." given.");
}
foreach($labels as $label){
$this->labels[] = $label;
}
}
public function getLabels() {
return $this->labels;
}
public function getSize() {
return $this->size;
}
}
이보기 도우미 클래스입니다 :
<?php
/**
* @namespace
*/
namespace ExecuteSurvey\Form\View\Helper;
/**
* @uses Zend\Form\ElementInterface
* @uses Zend\Form\View\helper\AbstractHelper
*/
use Zend\Form\ElementInterface;
use Zend\Form\View\Helper\AbstractHelper;
/**
* Class FormRadioMatrix which renders the actual element through a view
* @category ExecuteSurvey
* @package ExecuteSurvey_Form
* @subpackage ExecuteSurvey_Form_View
* @subpackage ExecuteSurvey_Form_View_Helper
*/
class FormRadioMatrix extends AbstractHelper {
/**
* Path to the .phtml file
* @var string
*/
protected $script = 'execute-survey/form-element/radiomatrix';
/**
* Method that renders the View Element
* @param \Zend\Form\ElementInterface $element
* @return \Zend\View\Renderer\RendererInterface
*/
public function __invoke(ElementInterface $element) {
return $this->getView()->render($this->script, array(
'element' => $element
));
}
}
그리고이 요소의 렌더링에 사용됩니다 radiomatrix.phtml입니다 : 나는 내 자신의 뷰를 작성하는 경우 그래서
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th></th>
<?php for ($i = 1; $i <= $element->getSize(); $i++): ?>
<th><?php echo $i ?></th>
<?php endfor; ?>
</tr>
</thead>
<tbody>
<?php foreach ($element->getLabels() as $key => $label): ?>
<tr>
<td><?php echo $label?></td>
<?php for($j = 1;$j<=$element->getSize();$j++):?>
<td><input type="radio" value="<?php echo $j?>" name="<?php echo $label.'X'.$key?>" id="<?php echo $element->getName().'X'.$key.'X'.$j?>"></td>
<?php endfor;?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
다행은 그것을 <3 고정 –