1

I am tring to call block from the controller action but its not working and throwing me an error as

Exception #0 (OutOfBoundsException): No element found with ID 'left'.

$this->_addContent($this->_view->getLayout()->createBlock('\Demo\Test\Block\Adminhtml\Method\Edit'));

$this->_addLeft($this->_view->getLayout()->createBlock('\Demo\Test\Block\Adminhtml\Method\Edit\Tabs'));

Can you please tell me how can i achieve above things?

2
  • From which controller, Its backend controller?
    – Sohel Rana
    Jul 14, 2016 at 6:44
  • Yes, Its a backend controller. Jul 14, 2016 at 11:17

1 Answer 1

1

First of all, you should not add blocks from the controller. Use the layout file for that.
But if you do, you need to call $this->_view->loadLayout() prior to adding your blocks.
and make sure your layout file has the main tag looking like this:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

layout="admin-2columns-left" ensures you that the left column exists.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.