1

I think I am misunderstanding the concepts of reference when it comes to controllers.

Reference class

<?php 

namespace Vendor\Module\Controller\Adminhtml\Index;

use Magento\Ui\Controller\Adminhtml\Index\Render;

class Render extends Render
{
    public function execute()
    {
        $component = $this->factory->create($this->_request->getParam('namespace'));
        $this->prepareComponent($component);
        if($this->_request->getParam('namespace')=='product_listing'){
            $this->_response->appendBody((string) $this->customFunction($component->render()));
        }
        else{
            $this->_response->appendBody((string) $component->render());
        }

        return parent::execute();
    }

    protected function customFunction($items){
        //code here...
    }
}

etc/adminhtml/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Ui\Controller\Adminhtml\Index\Render" type="Vendor\Module\Controller\Adminhtml\Index\Render" />
</config>

I receive a error:

 Initialization error component, check the spelling of the name or the correctness of the call.

What is wrong here ? What am I missing ?

EDIT :

I also found this https://github.com/magento/magento2/issues/3177 . They say it was a problem with the nginx configuration, but I am using apache 2.4 ...

Magento Version 2.0.2 CE

Any ideas ?

2 Answers 2

1

This line should throw an error:

class Render extends Render

you cannot use an alias the same as the class name you are creating.

Instead try this

use Magento\Ui\Controller\Adminhtml\Index\Render as CoreRender;

class Render extends CoreRender
6
  • no change... i flushed the cache and removed the cache, page_cache and generation directories as well, run setup:upgrade - no change Mar 1, 2016 at 15:12
  • I used a different alias before that, but the result was the same... Mar 1, 2016 at 15:28
  • I will vote up your answer, because you make a very good point anyway Mar 1, 2016 at 15:42
  • I made an update, if it can help ... ? I will continue looking Mar 1, 2016 at 16:04
  • 1
    sorry. I have no idea. I will post more if I find more.
    – Marius
    Mar 1, 2016 at 16:05
0

Ok, nevermind, the reason why it did not work was because I invoked

return parent::execute();

Once I removed that, everything started working just fine... I have absolutely no idea why... maybe I had some old info or something..

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.