how do you call Blocks in Controller Magento2?












6














I want getBlock Adb/Block/Index in controller Adb/Controller/Category/View. So How do it?



Edit



in controller.



namespace AddonFaqControllerCategory;


class View extends AddonFaqControllerCategory
{
/**
* @var MagentoFrameworkControllerResultForwardFactory
*/
protected $_coreRegistry = null;
/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory ;

/**
* @param MagentoBackendAppActionContext $context
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoFrameworkRegistry $registry

) {
$this->resultPageFactory = $resultPageFactory;
$this->_coreRegistry = $registry;
parent::__construct($context);
}

/**
* Product list page
*
* @return MagentoBackendModelViewResultPage
*/
public function execute()
{
$resultPage = $this->resultPageFactory ->create();
$blockInstance = $resultPage->getLayout()->getBlock('category.index');

}
}


layout in frontend



<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"> 
<body>
<referenceContainer name="content">
<block class="AddonFaqBlockFaq" name="category.index" template="Addon_Faq::view.phtml"/>
</referenceContainer>
</body>
</page>


It not call block Faq










share|improve this question




















  • 1




    You should not call blocks in controller. Why do you need it?
    – KAndy
    Oct 26 '15 at 16:36
















6














I want getBlock Adb/Block/Index in controller Adb/Controller/Category/View. So How do it?



Edit



in controller.



namespace AddonFaqControllerCategory;


class View extends AddonFaqControllerCategory
{
/**
* @var MagentoFrameworkControllerResultForwardFactory
*/
protected $_coreRegistry = null;
/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory ;

/**
* @param MagentoBackendAppActionContext $context
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoFrameworkRegistry $registry

) {
$this->resultPageFactory = $resultPageFactory;
$this->_coreRegistry = $registry;
parent::__construct($context);
}

/**
* Product list page
*
* @return MagentoBackendModelViewResultPage
*/
public function execute()
{
$resultPage = $this->resultPageFactory ->create();
$blockInstance = $resultPage->getLayout()->getBlock('category.index');

}
}


layout in frontend



<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"> 
<body>
<referenceContainer name="content">
<block class="AddonFaqBlockFaq" name="category.index" template="Addon_Faq::view.phtml"/>
</referenceContainer>
</body>
</page>


It not call block Faq










share|improve this question




















  • 1




    You should not call blocks in controller. Why do you need it?
    – KAndy
    Oct 26 '15 at 16:36














6












6








6


3





I want getBlock Adb/Block/Index in controller Adb/Controller/Category/View. So How do it?



Edit



in controller.



namespace AddonFaqControllerCategory;


class View extends AddonFaqControllerCategory
{
/**
* @var MagentoFrameworkControllerResultForwardFactory
*/
protected $_coreRegistry = null;
/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory ;

/**
* @param MagentoBackendAppActionContext $context
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoFrameworkRegistry $registry

) {
$this->resultPageFactory = $resultPageFactory;
$this->_coreRegistry = $registry;
parent::__construct($context);
}

/**
* Product list page
*
* @return MagentoBackendModelViewResultPage
*/
public function execute()
{
$resultPage = $this->resultPageFactory ->create();
$blockInstance = $resultPage->getLayout()->getBlock('category.index');

}
}


layout in frontend



<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"> 
<body>
<referenceContainer name="content">
<block class="AddonFaqBlockFaq" name="category.index" template="Addon_Faq::view.phtml"/>
</referenceContainer>
</body>
</page>


It not call block Faq










share|improve this question















I want getBlock Adb/Block/Index in controller Adb/Controller/Category/View. So How do it?



Edit



in controller.



namespace AddonFaqControllerCategory;


class View extends AddonFaqControllerCategory
{
/**
* @var MagentoFrameworkControllerResultForwardFactory
*/
protected $_coreRegistry = null;
/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory ;

/**
* @param MagentoBackendAppActionContext $context
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoFrameworkRegistry $registry

) {
$this->resultPageFactory = $resultPageFactory;
$this->_coreRegistry = $registry;
parent::__construct($context);
}

/**
* Product list page
*
* @return MagentoBackendModelViewResultPage
*/
public function execute()
{
$resultPage = $this->resultPageFactory ->create();
$blockInstance = $resultPage->getLayout()->getBlock('category.index');

}
}


layout in frontend



<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"> 
<body>
<referenceContainer name="content">
<block class="AddonFaqBlockFaq" name="category.index" template="Addon_Faq::view.phtml"/>
</referenceContainer>
</body>
</page>


It not call block Faq







magento2 magento2-dev-beta






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









treyBake

280115




280115










asked Oct 26 '15 at 9:00









xankaxanka

98331849




98331849








  • 1




    You should not call blocks in controller. Why do you need it?
    – KAndy
    Oct 26 '15 at 16:36














  • 1




    You should not call blocks in controller. Why do you need it?
    – KAndy
    Oct 26 '15 at 16:36








1




1




You should not call blocks in controller. Why do you need it?
– KAndy
Oct 26 '15 at 16:36




You should not call blocks in controller. Why do you need it?
– KAndy
Oct 26 '15 at 16:36










4 Answers
4






active

oldest

votes


















4














Your return nothing in your execute command. Return resultpage in your controller



    $resultPage = $this->resultPageFactory->create();

return $resultPage;


your xml name should be faq_category_view.xml.






share|improve this answer





























    17














    If you want to instantiate a block you need to add to inject in the constructor an instance of MagentoFrameworkViewLayoutFactory



    ...
    protected $layoutFactory;
    ...
    public function __construct(
    ...
    MagentoFrameworkViewLayoutFactory $layoutFactory,
    ...
    ) {
    ...
    $this->layoutFactory = $layoutFactory;
    ...
    }


    Then you can instantiate a block like this:



    $this->layoutFactory->create()->createBlock('BlockClassHere');


    if you want to access a block defined in the layout you need to inject in the constructor and instance of MagentoFrameworkViewResultPageFactory



    ...
    protected $resultPageFactory;
    ...
    public function __construct(
    ...
    MagentoFrameworkViewResultPageFactory $resultPageFactory,
    ...
    ) {
    ...
    $this->resultPageFactory = $resultPageFactory;
    ...
    }


    Then you will be able to access the block like this:



    $resultPage = $resultPageFactory->create();
    $blockInstance = $resultPage->getLayout()->getBlock('block.name.here');





    share|improve this answer























    • is this still the recommended way of calling the block? Can I not inject? :)
      – treyBake
      Dec 18 '18 at 16:43



















    9
















    1. Create the block:



       <?php
      namespace TrainingTestBlock;
      class Test extends MagentoFrameworkViewElementAbstractBlock
      {
      protected function _toHtml() {
      return "<b>Hello world from block!</b>";
      }
      }



    2. Create an action class:



      <?php
      namespace TrainingTestControllerBlock;
      class Index extends MagentoFrameworkAppActionAction
      {
      public function execute() {
      $layout = $this->_view->getLayout();
      $block = $layout->createBlock('TrainingTestBlockTest');
      $this->getResponse()->appendBody($block->toHtml());
      }
      }







    share|improve this answer























    • Do not use $this->_view in controllers. I read it is @deprecated. Use resultPage->getLayout() instead like the other answer suggests.
      – 7ochem
      Nov 21 '16 at 10:57



















    3














    See the core code:



    Step 1



    https://github.com/magento/magento2/blob/02e0378c33054acb0cdb8d731d1e2b2c2069bc1b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php#L26-L34



    public function __construct(
    MagentoBackendAppActionContext $context,
    MagentoFrameworkViewResultPageFactory $resultPageFactory,
    ) {
    parent::__construct($context);
    $this->resultPageFactory = $resultPageFactory;
    }


    Step 2



    https://github.com/magento/magento2/blob/02e0378c33054acb0cdb8d731d1e2b2c2069bc1b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php#L69-L70



    /** @var MagentoBackendModelViewResultPage $resultPage */
    $resultPage = $this->resultPageFactory->create();


    Step 3



    https://github.com/magento/magento2/blob/02e0378c33054acb0cdb8d731d1e2b2c2069bc1b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php#L119



    $block = $resultPage->getLayout()->getBlock('catalog.wysiwyg.js');





    share|improve this answer























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "479"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f87629%2fhow-do-you-call-blocks-in-controller-magento2%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      4














      Your return nothing in your execute command. Return resultpage in your controller



          $resultPage = $this->resultPageFactory->create();

      return $resultPage;


      your xml name should be faq_category_view.xml.






      share|improve this answer


























        4














        Your return nothing in your execute command. Return resultpage in your controller



            $resultPage = $this->resultPageFactory->create();

        return $resultPage;


        your xml name should be faq_category_view.xml.






        share|improve this answer
























          4












          4








          4






          Your return nothing in your execute command. Return resultpage in your controller



              $resultPage = $this->resultPageFactory->create();

          return $resultPage;


          your xml name should be faq_category_view.xml.






          share|improve this answer












          Your return nothing in your execute command. Return resultpage in your controller



              $resultPage = $this->resultPageFactory->create();

          return $resultPage;


          your xml name should be faq_category_view.xml.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Oct 26 '15 at 10:29









          Shaheer AliShaheer Ali

          1,35831125




          1,35831125

























              17














              If you want to instantiate a block you need to add to inject in the constructor an instance of MagentoFrameworkViewLayoutFactory



              ...
              protected $layoutFactory;
              ...
              public function __construct(
              ...
              MagentoFrameworkViewLayoutFactory $layoutFactory,
              ...
              ) {
              ...
              $this->layoutFactory = $layoutFactory;
              ...
              }


              Then you can instantiate a block like this:



              $this->layoutFactory->create()->createBlock('BlockClassHere');


              if you want to access a block defined in the layout you need to inject in the constructor and instance of MagentoFrameworkViewResultPageFactory



              ...
              protected $resultPageFactory;
              ...
              public function __construct(
              ...
              MagentoFrameworkViewResultPageFactory $resultPageFactory,
              ...
              ) {
              ...
              $this->resultPageFactory = $resultPageFactory;
              ...
              }


              Then you will be able to access the block like this:



              $resultPage = $resultPageFactory->create();
              $blockInstance = $resultPage->getLayout()->getBlock('block.name.here');





              share|improve this answer























              • is this still the recommended way of calling the block? Can I not inject? :)
                – treyBake
                Dec 18 '18 at 16:43
















              17














              If you want to instantiate a block you need to add to inject in the constructor an instance of MagentoFrameworkViewLayoutFactory



              ...
              protected $layoutFactory;
              ...
              public function __construct(
              ...
              MagentoFrameworkViewLayoutFactory $layoutFactory,
              ...
              ) {
              ...
              $this->layoutFactory = $layoutFactory;
              ...
              }


              Then you can instantiate a block like this:



              $this->layoutFactory->create()->createBlock('BlockClassHere');


              if you want to access a block defined in the layout you need to inject in the constructor and instance of MagentoFrameworkViewResultPageFactory



              ...
              protected $resultPageFactory;
              ...
              public function __construct(
              ...
              MagentoFrameworkViewResultPageFactory $resultPageFactory,
              ...
              ) {
              ...
              $this->resultPageFactory = $resultPageFactory;
              ...
              }


              Then you will be able to access the block like this:



              $resultPage = $resultPageFactory->create();
              $blockInstance = $resultPage->getLayout()->getBlock('block.name.here');





              share|improve this answer























              • is this still the recommended way of calling the block? Can I not inject? :)
                – treyBake
                Dec 18 '18 at 16:43














              17












              17








              17






              If you want to instantiate a block you need to add to inject in the constructor an instance of MagentoFrameworkViewLayoutFactory



              ...
              protected $layoutFactory;
              ...
              public function __construct(
              ...
              MagentoFrameworkViewLayoutFactory $layoutFactory,
              ...
              ) {
              ...
              $this->layoutFactory = $layoutFactory;
              ...
              }


              Then you can instantiate a block like this:



              $this->layoutFactory->create()->createBlock('BlockClassHere');


              if you want to access a block defined in the layout you need to inject in the constructor and instance of MagentoFrameworkViewResultPageFactory



              ...
              protected $resultPageFactory;
              ...
              public function __construct(
              ...
              MagentoFrameworkViewResultPageFactory $resultPageFactory,
              ...
              ) {
              ...
              $this->resultPageFactory = $resultPageFactory;
              ...
              }


              Then you will be able to access the block like this:



              $resultPage = $resultPageFactory->create();
              $blockInstance = $resultPage->getLayout()->getBlock('block.name.here');





              share|improve this answer














              If you want to instantiate a block you need to add to inject in the constructor an instance of MagentoFrameworkViewLayoutFactory



              ...
              protected $layoutFactory;
              ...
              public function __construct(
              ...
              MagentoFrameworkViewLayoutFactory $layoutFactory,
              ...
              ) {
              ...
              $this->layoutFactory = $layoutFactory;
              ...
              }


              Then you can instantiate a block like this:



              $this->layoutFactory->create()->createBlock('BlockClassHere');


              if you want to access a block defined in the layout you need to inject in the constructor and instance of MagentoFrameworkViewResultPageFactory



              ...
              protected $resultPageFactory;
              ...
              public function __construct(
              ...
              MagentoFrameworkViewResultPageFactory $resultPageFactory,
              ...
              ) {
              ...
              $this->resultPageFactory = $resultPageFactory;
              ...
              }


              Then you will be able to access the block like this:



              $resultPage = $resultPageFactory->create();
              $blockInstance = $resultPage->getLayout()->getBlock('block.name.here');






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Apr 8 '16 at 13:43









              Amit Bera

              57.3k1474170




              57.3k1474170










              answered Oct 26 '15 at 9:09









              MariusMarius

              163k28311660




              163k28311660












              • is this still the recommended way of calling the block? Can I not inject? :)
                – treyBake
                Dec 18 '18 at 16:43


















              • is this still the recommended way of calling the block? Can I not inject? :)
                – treyBake
                Dec 18 '18 at 16:43
















              is this still the recommended way of calling the block? Can I not inject? :)
              – treyBake
              Dec 18 '18 at 16:43




              is this still the recommended way of calling the block? Can I not inject? :)
              – treyBake
              Dec 18 '18 at 16:43











              9
















              1. Create the block:



                 <?php
                namespace TrainingTestBlock;
                class Test extends MagentoFrameworkViewElementAbstractBlock
                {
                protected function _toHtml() {
                return "<b>Hello world from block!</b>";
                }
                }



              2. Create an action class:



                <?php
                namespace TrainingTestControllerBlock;
                class Index extends MagentoFrameworkAppActionAction
                {
                public function execute() {
                $layout = $this->_view->getLayout();
                $block = $layout->createBlock('TrainingTestBlockTest');
                $this->getResponse()->appendBody($block->toHtml());
                }
                }







              share|improve this answer























              • Do not use $this->_view in controllers. I read it is @deprecated. Use resultPage->getLayout() instead like the other answer suggests.
                – 7ochem
                Nov 21 '16 at 10:57
















              9
















              1. Create the block:



                 <?php
                namespace TrainingTestBlock;
                class Test extends MagentoFrameworkViewElementAbstractBlock
                {
                protected function _toHtml() {
                return "<b>Hello world from block!</b>";
                }
                }



              2. Create an action class:



                <?php
                namespace TrainingTestControllerBlock;
                class Index extends MagentoFrameworkAppActionAction
                {
                public function execute() {
                $layout = $this->_view->getLayout();
                $block = $layout->createBlock('TrainingTestBlockTest');
                $this->getResponse()->appendBody($block->toHtml());
                }
                }







              share|improve this answer























              • Do not use $this->_view in controllers. I read it is @deprecated. Use resultPage->getLayout() instead like the other answer suggests.
                – 7ochem
                Nov 21 '16 at 10:57














              9












              9








              9








              1. Create the block:



                 <?php
                namespace TrainingTestBlock;
                class Test extends MagentoFrameworkViewElementAbstractBlock
                {
                protected function _toHtml() {
                return "<b>Hello world from block!</b>";
                }
                }



              2. Create an action class:



                <?php
                namespace TrainingTestControllerBlock;
                class Index extends MagentoFrameworkAppActionAction
                {
                public function execute() {
                $layout = $this->_view->getLayout();
                $block = $layout->createBlock('TrainingTestBlockTest');
                $this->getResponse()->appendBody($block->toHtml());
                }
                }







              share|improve this answer
















              1. Create the block:



                 <?php
                namespace TrainingTestBlock;
                class Test extends MagentoFrameworkViewElementAbstractBlock
                {
                protected function _toHtml() {
                return "<b>Hello world from block!</b>";
                }
                }



              2. Create an action class:



                <?php
                namespace TrainingTestControllerBlock;
                class Index extends MagentoFrameworkAppActionAction
                {
                public function execute() {
                $layout = $this->_view->getLayout();
                $block = $layout->createBlock('TrainingTestBlockTest');
                $this->getResponse()->appendBody($block->toHtml());
                }
                }








              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 4 '15 at 12:14

























              answered Nov 4 '15 at 11:58









              Rakesh JesadiyaRakesh Jesadiya

              28.6k1571119




              28.6k1571119












              • Do not use $this->_view in controllers. I read it is @deprecated. Use resultPage->getLayout() instead like the other answer suggests.
                – 7ochem
                Nov 21 '16 at 10:57


















              • Do not use $this->_view in controllers. I read it is @deprecated. Use resultPage->getLayout() instead like the other answer suggests.
                – 7ochem
                Nov 21 '16 at 10:57
















              Do not use $this->_view in controllers. I read it is @deprecated. Use resultPage->getLayout() instead like the other answer suggests.
              – 7ochem
              Nov 21 '16 at 10:57




              Do not use $this->_view in controllers. I read it is @deprecated. Use resultPage->getLayout() instead like the other answer suggests.
              – 7ochem
              Nov 21 '16 at 10:57











              3














              See the core code:



              Step 1



              https://github.com/magento/magento2/blob/02e0378c33054acb0cdb8d731d1e2b2c2069bc1b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php#L26-L34



              public function __construct(
              MagentoBackendAppActionContext $context,
              MagentoFrameworkViewResultPageFactory $resultPageFactory,
              ) {
              parent::__construct($context);
              $this->resultPageFactory = $resultPageFactory;
              }


              Step 2



              https://github.com/magento/magento2/blob/02e0378c33054acb0cdb8d731d1e2b2c2069bc1b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php#L69-L70



              /** @var MagentoBackendModelViewResultPage $resultPage */
              $resultPage = $this->resultPageFactory->create();


              Step 3



              https://github.com/magento/magento2/blob/02e0378c33054acb0cdb8d731d1e2b2c2069bc1b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php#L119



              $block = $resultPage->getLayout()->getBlock('catalog.wysiwyg.js');





              share|improve this answer




























                3














                See the core code:



                Step 1



                https://github.com/magento/magento2/blob/02e0378c33054acb0cdb8d731d1e2b2c2069bc1b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php#L26-L34



                public function __construct(
                MagentoBackendAppActionContext $context,
                MagentoFrameworkViewResultPageFactory $resultPageFactory,
                ) {
                parent::__construct($context);
                $this->resultPageFactory = $resultPageFactory;
                }


                Step 2



                https://github.com/magento/magento2/blob/02e0378c33054acb0cdb8d731d1e2b2c2069bc1b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php#L69-L70



                /** @var MagentoBackendModelViewResultPage $resultPage */
                $resultPage = $this->resultPageFactory->create();


                Step 3



                https://github.com/magento/magento2/blob/02e0378c33054acb0cdb8d731d1e2b2c2069bc1b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php#L119



                $block = $resultPage->getLayout()->getBlock('catalog.wysiwyg.js');





                share|improve this answer


























                  3












                  3








                  3






                  See the core code:



                  Step 1



                  https://github.com/magento/magento2/blob/02e0378c33054acb0cdb8d731d1e2b2c2069bc1b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php#L26-L34



                  public function __construct(
                  MagentoBackendAppActionContext $context,
                  MagentoFrameworkViewResultPageFactory $resultPageFactory,
                  ) {
                  parent::__construct($context);
                  $this->resultPageFactory = $resultPageFactory;
                  }


                  Step 2



                  https://github.com/magento/magento2/blob/02e0378c33054acb0cdb8d731d1e2b2c2069bc1b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php#L69-L70



                  /** @var MagentoBackendModelViewResultPage $resultPage */
                  $resultPage = $this->resultPageFactory->create();


                  Step 3



                  https://github.com/magento/magento2/blob/02e0378c33054acb0cdb8d731d1e2b2c2069bc1b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php#L119



                  $block = $resultPage->getLayout()->getBlock('catalog.wysiwyg.js');





                  share|improve this answer














                  See the core code:



                  Step 1



                  https://github.com/magento/magento2/blob/02e0378c33054acb0cdb8d731d1e2b2c2069bc1b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php#L26-L34



                  public function __construct(
                  MagentoBackendAppActionContext $context,
                  MagentoFrameworkViewResultPageFactory $resultPageFactory,
                  ) {
                  parent::__construct($context);
                  $this->resultPageFactory = $resultPageFactory;
                  }


                  Step 2



                  https://github.com/magento/magento2/blob/02e0378c33054acb0cdb8d731d1e2b2c2069bc1b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php#L69-L70



                  /** @var MagentoBackendModelViewResultPage $resultPage */
                  $resultPage = $this->resultPageFactory->create();


                  Step 3



                  https://github.com/magento/magento2/blob/02e0378c33054acb0cdb8d731d1e2b2c2069bc1b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php#L119



                  $block = $resultPage->getLayout()->getBlock('catalog.wysiwyg.js');






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 7 '16 at 8:53









                  Siarhey Uchukhlebau

                  9,33192757




                  9,33192757










                  answered Oct 26 '15 at 9:11









                  Mage2.PROMage2.PRO

                  3,54211218




                  3,54211218






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Magento Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f87629%2fhow-do-you-call-blocks-in-controller-magento2%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      An IMO inspired problem

                      Management

                      Investment