답변:
블록과 하위 블록이 종료되는 레이아웃을로드하는 컨트롤러가 동일한 지 확인하십시오.
Magento \ Backend \ App \ Action \ Context를 사용하십시오.
Magento \ Framework \ View \ Result \ PageFactory를 사용하십시오.
Edit 클래스는 \ Magento \ Backend \ App \ Action을 확장합니다.
{
보호 된 $ resultPageFactory;
공공 함수 __construct (
문맥 $ context,
PageFactory $ resultPageFactory
) {
$ this-> resultPageFactory = $ resultPageFactory;
parent :: __ construct ($ 문맥);
}
$ resultPage = $ this-> resultPageFactory-> create ();
$ blockInstance = $ resultPage-> getLayout ()-> getBlock ( 'your.block.name');
$ childBlocks = $ blockInstance-> getChildNames ();
foreach ($ childBlocks as $ blockName) {
$ block = $ resultPage-> getLayout ()-> getBlock ($ blockName);
}
}
$blockInstance->getChildNames();여기 getChildNames () 의미합니까?
이런 식으로 모든 자식 블록을 얻을 수 있습니다.
$allblocks = $block->getChildNames();
foreach($allblocks as $blocks){
$child_block = $this->resultPageFactory->create()->getLayout()->getBlock($blocks);
}