2016-06-30 1 views
0

새 항목을 작성할 수있는 frontend 플러그인이있는 typo3 확장을 만들었습니다.'foreign_table` 옵션으로 채워진 유체로 선택 필드 표시

하나의 필드는 다른 테이블의 값을 가진 선택 필드입니다. TCA에서 다음과 같이 보입니다.

'shoeref' => array(
    'exclude' => 0, 
    'label' => 'Shoe Ref Test', 
    'config' => array(
     'type' => 'select', 
     'foreign_table' => 'tx_testcollection_domain_model_testcollection', 
     'foreign_table_where' => 'and tx_testcollection_domain_model_testcollection.pid = 96 and tx_testcollection_domain_model_testcollection.sys_language_uid = 0', 
     'minitems' => 0, 
     'maxitems' => 1, 
    ), 
), 

이것은 백엔드에서 작동합니다. 테이블 tx_testcollection_domain_model_testcollection에서 레코드를 선택할 수 있으며이 프런트 엔드에서이 요소에 액세스 할 수 있습니다.

하지만 '새 페이지'(새 요소를 만들 수 있음)에는 선택 필드를 채우는 방법에 대한 실마리가 없습니다.

<f:form.select property="shoeref" /> 

을하지만 I '옵션이'필요하다 말한다 :

는 그냥 시도했다. 이 같은
뭔가 :

<f:form.select property="shoeref" options="{0: 'test1', 1: 'test2'}"/> 

그러나 물론 나는이 selectfield 테이블 tx_testcollection_domain_model_testcollection에서 값이 필요합니다.

그래서 어떻게이 선택 필드에 같은 테이블의 값을 얻을 수 있습니까?


편집 나는 가까운 이니

$collection = $this->objectManager->get('Test\TestCollection\Domain\Repository\TestCollectionRepository'); 

    $querySettings = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings'); 
    $querySettings->setRespectStoragePage(FALSE); 
    $querySettings->setStoragePageIds(array(96)); //Looks like he dont care about this and just finds all.. 

    $collection->setDefaultQuerySettings($querySettings); 
    $this->view->assign('collecton',$collection->findAll()); 

그리고 템플릿에 :
은 내가 newAction에 내 컨트롤러에서 변수를 채울

<f:form.select property="shoeref" options="{collecton}" optionLabelField="name"/> 

내가 권리를 참조 옵션을 사용하지만 저장하고 싶을 때 얻을 수 있습니다.

,210
Exception while property mapping at property path "": PHP Catchable Fatal Error: Argument 1 passed to Test\TestCustomerfeedback\Domain\Model\Customerfeedback::setShoeref() must be an instance of 
Test\TestCustomerfeedback\Domain\Model\Test\TestCollection\Domain\Model\TestCollection 
, instance of 
Test\TestCollection\Domain\Model\TestCollection 
given 

, called in /home/www-data/typo3_src-7.6.4_dev/typo3/sysext/extbase/Classes/Reflection/ObjectAccess.php on line 209 and defined in /home/www-data/mydomain/typo3conf/ext/test_customerfeedback/Classes/Domain/Model/Customerfeedback.php line 32 

답변

1

methoid Test\TestCustomerfeedback\Domain\Model\Customerfeedback::setShoeref()의 인수에 대한 유형 힌트가 잘못 - 아마 다음과 같습니다

public function setShoeref(Test\TestCollection\Domain\Model\TestCollection $shoeRef) 
{ 
    // ... 
} 

그것은 아마 다음과 같아야합니다 다음에

public function setShoeref(\Test\TestCollection\Domain\Model\TestCollection $shoeRef) 
{ 
    // ... 
} 

(추가 백 슬래시 매개 변수 유형)

머리글에 use 문을 추가하거나이 특별한 경우 (sinc 전자 두 클래스 CustomerFeedbackTestCollection가 같은 공간에있는), 단지 형 힌트로 짧은 TestCollection를 사용

<?php 

public function setShoeref(TestCollection $shoeRef) 
{ 
    // ... 
} 

또 한가지 : 클래스로 주입, 개체 관리자를 사용하여 저장소를 가져 오지 마십시오 그들을 포함하는 속성을 보호해야하고, 필요한 클래스를 @var 주석으로 추가하고 주석 @inject을 추가하면됩니다. 그런 다음 해당 코드를 다시 실행하기 전에 설치 도구에서 캐시를 지우십시오.

/** 
* @var \Test\TestCollection\Domain\Repository\TestCollectionRepository 
* @inject 
*/ 
protected $collectionRepository; 
+0

감사! '@ 인제'는 내가 찾고 있던 것입니다. (나는 그것을 보지 않아서 눈이 멀었다) – nbar