gpt4 book ai didi

magento2 - Magento 2.1.1 无效的 block 类型异常 - 找不到类

转载 作者:行者123 更新时间:2023-12-04 13:41:36 25 4
gpt4 key购买 nike

尝试加载自定义模块的编辑/创建表单。

在我的生产系统 (linux) 上的 Magento 2.1.1 中,我得到了一个无效的 block 类型异常,这是由找不到类引起的,而在我的本地主机 xampp/windows 上一切正常。当我想在网格正常工作时打开表单以创建或编辑自定义实体时发生。

2 exception(s):
Exception #0 (Magento\Framework\Exception\LocalizedException): Invalid block type: Brainworx\Medipimsync\Block\Adminhtml\Sync\Edit\Form
Exception #1 (ReflectionException): Class Brainworx\Medipimsync\Block\Adminhtml\Sync\Edit\Form does not exist

Exception #0 (Magento\Framework\Exception\LocalizedException): Invalid block type: Brainworx\Medipimsync\Block\Adminhtml\Sync\Edit\Form
#0 /data/sites/web/apovitabe/www/vendor/magento/framework/View/Layout/Generator/Block.php(237): Magento\Framework\View\Layout\Generator\Block->getBlockInstance('Brainworx\\Medip...', Array)
#1 /data/sites/web/apovitabe/www/vendor/magento/framework/View/Layout.php(760): Magento\Framework\View\Layout\Generator\Block->createBlock('Brainworx\\Medip...', 'medipimsync_syn...', Array)
#2 /data/sites/web/apovitabe/www/vendor/magento/framework/View/Layout.php(743): Magento\Framework\View\Layout->_createBlock('Brainworx\\Medip...', 'medipimsync_syn...', Array)
#3 /data/sites/web/apovitabe/www/var/generation/Magento/Framework/View/Layout/Interceptor.php(349): Magento\Framework\View\Layout->createBlock('Brainworx\\Medip...', 'medipimsync_syn...', Array)
#4 /data/sites/web/apovitabe/www/vendor/magento/framework/View/Element/AbstractBlock.php(382): Magento\Framework\View\Layout\Interceptor->createBlock('Brainworx\\Medip...', 'medipimsync_syn...', Array)
#5 /data/sites/web/apovitabe/www/vendor/magento/module-backend/Block/Widget/Form/Container.php(108): Magento\Framework\View\Element\AbstractBlock->addChild('form', 'Brainworx\\Medip...')
#6 /data/sites/web/apovitabe/www/vendor/magento/framework/View/Element/AbstractBlock.php(264): Magento\Backend\Block\Widget\Form\Container->_prepareLayout()
#7 /data/sites/web/apovitabe/www/vendor/magento/framework/View/Layout/Generator/Block.php(139): Magento\Framework\View\Element\AbstractBlock->setLayout(Object(Magento\Framework\View\Layout\Interceptor))
#8 /data/sites/web/apovitabe/www/vendor/magento/framework/View/Layout/GeneratorPool.php(86): Magento\Framework\View\Layout\Generator\Block->process(Object(Magento\Framework\View\Layout\Reader\Context), Object(Magento\Framework\View\Layout\Generator\Context))
#9 /data/sites/web/apovitabe/www/vendor/magento/framework/View/Layout.php(327): Magento\Framework\View\Layout\GeneratorPool->process(Object(Magento\Framework\View\Layout\Reader\Context), Object(Magento\Framework\View\Layout\Generator\Context))
#10 /data/sites/web/apovitabe/www/var/generation/Magento/Framework/View/Layout/Interceptor.php(89): Magento\Framework\View\Layout->generateElements()
#11 /data/sites/web/apovitabe/www/vendor/magento/framework/View/Layout/Builder.php(129): Magento\Framework\View\Layout\Interceptor->generateElements()
#12 /data/sites/web/apovitabe/www/vendor/magento/framework/View/Page/Builder.php(55): Magento\Framework\View\Layout\Builder->generateLayoutBlocks()
#13 /data/sites/web/apovitabe/www/vendor/magento/framework/View/Layout/Builder.php(65): Magento\Framework\View\Page\Builder->generateLayoutBlocks()
#14 /data/sites/web/apovitabe/www/vendor/magento/framework/View/Layout.php(244): Magento\Framework\View\Layout\Builder->build()
#15 /data/sites/web/apovitabe/www/vendor/magento/framework/View/Layout.php(859): Magento\Framework\View\Layout->build()
#16 /data/sites/web/apovitabe/www/var/generation/Magento/Framework/View/Layout/Interceptor.php(414): Magento\Framework\View\Layout->getBlock('menu')
#17 /data/sites/web/apovitabe/www/vendor/magento/module-backend/Model/View/Result/Page.php(59): Magento\Framework\View\Layout\Interceptor->getBlock('menu')
#18 /data/sites/web/apovitabe/www/var/generation/Magento/Backend/Model/View/Result/Page/Interceptor.php(24): Magento\Backend\Model\View\Result\Page->setActiveMenu('Brainworx_Medip...')
#19 /data/sites/web/apovitabe/www/app/code/brainworx/medipimsync/Controller/Adminhtml/Sync/Edit.php(52): Magento\Backend\Model\View\Result\Page\Interceptor->setActiveMenu('Brainworx_Medip...')
#20 /data/sites/web/apovitabe/www/app/code/brainworx/medipimsync/Controller/Adminhtml/Sync/Edit.php(87): brainworx\medipimsync\Controller\Adminhtml\Sync\Edit->_initAction()
#21 /data/sites/web/apovitabe/www/var/generation/brainworx/medipimsync/Controller/Adminhtml/Sync/Edit/Interceptor.php(24): brainworx\medipimsync\Controller\Adminhtml\Sync\Edit->execute()
#22 /data/sites/web/apovitabe/www/vendor/magento/framework/App/Action/Action.php(102): brainworx\medipimsync\Controller\Adminhtml\Sync\Edit\Interceptor->execute()
#23 /data/sites/web/apovitabe/www/vendor/magento/module-backend/App/AbstractAction.php(226): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))
#24 /data/sites/web/apovitabe/www/vendor/magento/framework/Interception/Interceptor.php(74): Magento\Backend\App\AbstractAction->dispatch(Object(Magento\Framework\App\Request\Http))
#25 /data/sites/web/apovitabe/www/vendor/magento/framework/Interception/Chain/Chain.php(70): brainworx\medipimsync\Controller\Adminhtml\Sync\Edit\Interceptor->___callParent('dispatch', Array)
#26 /data/sites/web/apovitabe/www/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('brainworx\\medip...', 'dispatch', Object(brainworx\medipimsync\Controller\Adminhtml\Sync\Edit\Interceptor), Array, 'adminAuthentica...')

设置:

register.php

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'brainworx_medipimsync',
__DIR__
);

etc/Module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="brainworx_medipimsync" setup_version="1.0.4" />
</config>

表单类存在 app\code\brainworx\medipimsync\Block\Adminhtml\Sync\Edit\Form.php

namespace brainworx\medipimsync\Block\Adminhtml\Sync\Edit;

use Magento\Backend\Block\Template\Context;
use Magento\Framework\Registry;
use Magento\Framework\Data\FormFactory;
use Magento\Store\Model\System\Store;
use Magento\Backend\Model\Auth\Session;

/**
* Adminhtml sync edit form
*/
class Form extends \Magento\Backend\Block\Widget\Form\Generic
{

/**
* @var \Magento\Store\Model\System\Store
*/
protected $_systemStore;
protected $_loginUser;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\Data\FormFactory $formFactory
* @param \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig
* @param \Magento\Store\Model\System\Store $systemStore
* @param array $data
* @param \Magento\backend\Model\Auth\Session $authSession
*/
public function __construct(
Context $context,Registry $registry,FormFactory $formFactory,Store $systemStore,
array $data = [],Session $authSession
) {
$this->_systemStore = $systemStore;
$this->_loginUser = $authSession->getUser()->getUsername();
parent::__construct($context, $registry, $formFactory, $data);
}

/**
* Init form
*
* @return void
*/
protected function _construct()
{
parent::_construct();
$this->setId('sync_form');
$this->setTitle(__('Sync Information'));
}

/**
* Prepare form
*
* @return $this
*/
protected function _prepareForm()
{
/** @var \brainworx\medipimsync\Model\Sync $model */
$model = $this->_coreRegistry->registry('medipimsync_sync');

/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create(
['data' => ['id' => 'edit_form','action' => $this->getData('action'), 'method' => 'post']]
);

$form->setHtmlIdPrefix('sync_');

$fieldset = $form->addFieldset(
'base_fieldset',
['legend' => __('General Information'), 'class' => 'fieldset-wide']
);

$fieldset->addField(
'title',
'text',
['name' => 'user', 'label' => __('User'), 'title' => __('User'), 'required' => true,
'value' => $this->_loginUser , 'readonly' => true
]
);

$fieldset->addField(
'entity',
'select',
[
'label' => __('Entity'),
'title' => __('Entity'),
'name' => 'entity',
'required' => true,
'options' => ['PROD' => __('Products'), 'CAT' => __('Categories')]
]
);

//$form->setValues($model->getData());
$form->setUseContainer(true);
$this->setForm($form);

return parent::_prepareForm();
}
}

编辑类还有包含表单的编辑类app\code\brainworx\medipimsync\Block\Adminhtml\Sync\Edit.php

namespace brainworx\medipimsync\Block\Adminhtml\Sync;

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 = []
) {
$this->_coreRegistry = $registry;
parent::__construct($context, $data);
}

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

parent::_construct();

if ($this->_isAllowedAction('Brainworx_Medipimsync::save')) {
$this->buttonList->update('save', 'label', __('Creatae new'));
$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');
}
}

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

/**
* 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('medipimsync/*/save', ['_current' => true, 'back' => 'edit', 'active_tab' => '']);
}
}

布局文件以及加载编辑类的布局文件:view/adminhtml/layout/medipimsync_sync_edit.xml

<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="brainworx\medipimsync\Block\Adminhtml\Sync\Edit" name="medipimsync_sync_edit"/>
</referenceContainer>
</body>
</page>

感谢您的帮助!

最佳答案

经过一天一夜的搜索,已经找到了解决方案。

对于那些想知道的人:你应该使目录和模块名称大写。将所有内容更改为 Brainworx\Medipimsync 就可以了!因此,app/code 下的目录都作为模块名称和命名空间。

关于magento2 - Magento 2.1.1 无效的 block 类型异常 - 找不到类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39683526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com