0

I have a custom form with block that I want to load, but everytime I call the controller to load the form I always got this error=

Fatal error: Uncaught Error: Class 'Lime\Courier\Block\Adminhtml\Preferences\Edit' not found in C:\xampp7\htdocs\magento2\vendor\magento\framework\ObjectManager\Factory\AbstractFactory.php:93

I already make sure the block folder structure is right and first folder and file name start with capital letter, I also already delete var/generation folder and run setup:di:compile, but nothing works

here's my xml layout code :

<?xml version="1.0" ?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="editor"/>
    <body>
        <referenceContainer name="content">
            <block class="Lime\Courier\Block\Adminhtml\Preferences\Edit" name="lime_courier_preferences_edit"/>
        </referenceContainer>
    </body>
</page>

in Lime\Courier\Block\Adminhtml\Preferences\Edit directory I have Edit.php :

<?php
namespace Lime\Courier\Block\Adminhtml\Preferences\Edit;

class Edit extends \Magento\Backend\Block\Widget\Form\Container
{
    /**
     * Core registry
     *
     * @var \Magento\Framework\Registry
     */
    protected $_coreRegistry = null;

    /**
     * @param \Magento\Backend\Block\Widget\Context $context
     * @param \Magento\Framework\Registry $registry
     * @param array $data
     */
    public function __construct(
        \Magento\Backend\Block\Widget\Context $context,
        \Magento\Framework\Registry $registry,
        array $data = []
    ) {
      die('a');
        $this->_coreRegistry = $registry;
        parent::__construct($context, $data);
    }

    /**
     * Initialize blog post edit block
     *
     * @return void
     */
    protected function _construct()
    {
        $this->_objectId = 'preferences_id';
        $this->_blockGroup = 'Lime_Courier';
        $this->_controller = 'lime_courier';

        parent::_construct();

        if ($this->_isAllowedAction('Lime_Courier::save')) {
            $this->buttonList->update('save', 'label', __('Save Courier Preferences'));
            $this->buttonList->add(
                'saveandcontinue',
                [
                    'label' => __('Save and Continue Edit'),
                    'class' => 'save',
                    'data_attribute' => [
                        'mage-init' => [
                            'button' => ['event' => 'saveAndContinueEdit', 'target' => '#edit_form'],
                        ],
                    ]
                ],
                -100
            );
        } else {
            $this->buttonList->remove('save');
        }

        if ($this->_isAllowedAction('Lime_Courier::preferences_delete')) {
            $this->buttonList->update('delete', 'label', __('Delete Preferences'));
        } else {
            $this->buttonList->remove('delete');
        }
    }

    /**
     * Retrieve text for header element depending on loaded post
     *
     * @return \Magento\Framework\Phrase
     */
    public function getHeaderText()
    {
        if ($this->_coreRegistry->registry('lime_courier')->getId()) {
            return __("Edit Preferences '%1'", $this->escapeHtml($this->_coreRegistry->registry('lime_courier')->getTitle()));
        } else {
            return __('Lime Courier');
        }
    }

    /**
     * Check permission for passed action
     *
     * @param string $resourceId
     * @return bool
     */
    protected function _isAllowedAction($resourceId)
    {
        return $this->_authorization->isAllowed($resourceId);
    }

    /**
     * Getter of url for "Save and Continue" button
     * tab_id will be replaced by desired by JS later
     *
     * @return string
     */
    protected function _getSaveAndContinueUrl()
    {
        return $this->getUrl('courier/*/save', ['_current' => true, 'back' => 'edit', 'active_tab' => '']);
    }
}
2
  • have you tried my solution?
    – Bojjaiah
    Commented Jan 20, 2017 at 6:58
  • If it working please up vote my answer.
    – Bojjaiah
    Commented Jan 20, 2017 at 7:01

4 Answers 4

0

change your xml file

<?xml version="1.0" ?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="editor"/>
    <body>
        <referenceContainer name="content">
            <block class="Lime\Courier\Block\Adminhtml\Preferences\Edit" name="lime_courier_preferences_edit"/>
        </referenceContainer>
    </body>
</page>

to

<?xml version="1.0" ?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="editor"/>
    <body>
        <referenceContainer name="content">
            <block class="Lime\Courier\Block\Adminhtml\Preferences\Edit\Edit" name="lime_courier_preferences_edit"/>
        </referenceContainer>
    </body>
</page>

You missed a Class name from xml file.

0

Change you class namespace & remove last edit directory as your overridden file path is Lime\Courier\Block\Adminhtml\Preferences\Edit :

 namespace Lime\Courier\Block\Adminhtml\Preferences;

 class Edit extends \Magento\Backend\Block\Widget\Form\Container
 {
   ....
   ....
 }
0

remove Edit from your class namespace

namespace Lime\Courier\Block\Adminhtml\Preferences\Edit

to

namespace Lime\Courier\Block\Adminhtml\Preferences

1
  • still not working Commented Jan 20, 2017 at 6:25
0

The problem is due to the namespace. Magento is trying to find Edit.php class in Lime\Courier\Block\Adminhtml\Preferences\Edit

Change the line

namespace Lime\Courier\Block\Adminhtml\Preferences\Edit;

to

namespace Lime\Courier\Block\Adminhtml\Preferences;

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.