나는 다음과 같은 메시지가 도착 형태로 작업을 호출하는 URL을 실행할 때마다 다음 경우젠드 프레임 워크 2 양식 필드 집합 오류
Zend\Form\Fieldset::add requires that $elementOrFieldset be an object implementing Zend\Form\ElementInterface; received "string"
내 스택 :
# 0 /Users/cesar/Documents/zf2course/vendor/zendframework/zend-form/src/Form.php(179) 젠드 \ 양식 \ Fieldset-> ("위치"배열)을 추가
# 1/사용자/cesar/Documents/zf2course/module/Application/src/Application/Form/Info. php (69) : Zend \ Form \ Form-> add ('위치')
# 2 /Users/cesar/Documents/zf2course/module/Application/Controller/IndexController.php(25) : 응용 프로그램 \ 형식 \ 정보 -> __ 구조()
# 3 /Users/cesar/Documents/zf2course/vendor/zendframework/zend-mvc/src/Controller/AbstractActionController.php(82) : Application \ Controller \ IndexController- > infoAction()
# 4 내부 기능] 젠드 \ MVC \ 컨트롤러 \ AbstractActionController-> onDispatch (개체 (젠드 \ MVC \ MvcEvent))
# 5/사용자/자르/문서/zf2course/벤더/젠드 프램 ework/zend-eventmanager/src/EventManager.php (490) : call_user_func (배열, 객체 (젠드) /src/EventManager.php(263) : Zend \ EventManager \ EventManager-> triggerListeners ('디스패치', 객체 (Zend \ Mvc \ MvcEvent), 객체 (클로저))
# 7/Users/cesar/Documents/Zend \ EventManager \ EventManager-> triggerEventUntil (Object (Closure), Object (Zend \ Mvc \ MvcEvent))
# 8 /Users/cesar/Documents/zf2course/vendor/zendframework/zend-mvc/src/DispatchListener.php(118) : Zend \ Mvc \ Controller \ Abstra
# 9 [내부 기능] : Zend \ Mvc \ DispatchListener-> onDispatch (Object (Zend \ Http \ PhpEnvironment \ Response) \ MVC \ MvcEvent))
# 10 /Users/cesar/Documents/zf2course/vendor/zendframework/zend-eventmanager/src/EventManager.php(490) : call_user_func (배열, 객체 (젠드 \ MVC \ MvcEvent))
# 11 /Users//Documents/zf2course/vendor/zendframework/zend-eventmanager/src/EventManager.php(263) : Zend \ EventManager \ EventManager-> triggerListeners ('dispatch', Object (Zend \ Mvc \ MvcEvent), 객체 (Closure)
# 12 /Users/cesar/Documents/zf2course/vendor/zendframework/zend-mvc/src/Application.php(340) : Zend \ EventManager \ EventManager-> triggerEventUntil (Object (Closure), Object (Zend \ Mvc \ MvcEvent))
# 13/사용자/Cesar/Documents/zf2course/public/index.PHP (21) : 젠드 \ MVC \ 응용 프로그램 -> 실행()
# {주} (14)는
나는 다음과 같이 Form 클래스를 만듭니다
<?php
namespace Application\Form;
use Zend\Form\Form;
use Zend\Form\Element;
class Info extends Form
{
public function __construct()
{
parent::__construct('info');
$location = new Element('location');
$location->setLabel('Location');
$location->setAttribute(array(
'type' => 'text',
'class' => 'form-control',
));
$sizeW = new Element\Number('size_w');
$sizeW->setLabel('Width Size');
$sizeW->setAttributes(array(
'min' => '0',
'max' => '500',
'step' => '0.1',
'class' => 'form-control'
));
$sizeH = new Element\Number('size_h');
$sizeH->setLabel('Height Size');
$sizeH->setAttributes(array(
'min' => '0',
'max' => '500',
'step' => '0.1',
'class' => 'form-control'
));
$type = new Element\Select('plot_type');
$type->setLabel('Plot Type');
$type->setAttribute('class', 'form-control');
$type->setValueOptions(array(
1 => 'Balcony',
2 => 'Plot',
));
$family = new Element\Number('family');
$family->setLabel('Family Aggregate Number');
$family->setAttributes(array(
'min' => '0',
'max' => '10',
'step' => '1',
'class' => 'form-control'
));
$diff = new Element\Select('diff');
$diff->setLabel('Gardening Type');
$diff->setAttribute('class', 'form-control');
$diff->setValueOptions(array(
1 => 'Begginner',
2 => 'Advanced',
));
$submit = new Element\Submit('submit');
$submit->setValue('Submit');
$submit->setAttribute('class', 'btn btn-primary');
$this->add('location');
$this->add('size_w');
$this->add('size_h');
$this->add('plot_type');
$this->add('family');
$this->add('diff');
$this->add('submit');
}
}
그리고 나는 infocontroller라고 그래서 같은 양식 :
...
public function infoAction()
{
$form = new Info();
if ($this->request->isPost())
{
$form->setData($this->request->getPost());
// save stuff
}
return new ViewModel(array(
'form' => $form,
));
}
오전 내가 모르는 뭔가가 아니면이 필드 셋 클래스를 만드는 데 필요한 않았고, 그것이 나에게이 오류를주고 그 이유는? 만약 누군가 좋은 zf2 튜토리얼을 보내 주시면 아주 좋을 것 같습니다.
내가 튜토리얼을 잘못 읽고있는 것 같아요. 나는 또한 그 튜토리얼을 따르고 있었지만 다소 혼란 스럽다. 어쩌면 ZF가 지금은 나에게 너무 앞서 있지만 노력 중입니다. 트릭을 만들었고 양식을 작동시킬 수있었습니다. 감사 –