Класс модели не найден в.../magento/framework/ObjectManager/Factory/AbstractFactory.php:93
Когда я пытаюсь загрузить коллекцию с помощью метода getCollection
в своем пользовательском блоке, я получаю эту ошибку в журнале apache2.
Полная ошибка:
[Пн. 08 мая 09:53:53.485661 2017] [proxy_fcgi:ошибка] [pid 1996: tid 140084720269056] [клиент 127.0.0.1:50323] AH01071: Получено сообщение об ошибке PHP:
Неустранимая ошибка PHP: Неперехваченная ошибка: Класс 'Ciptaloka\\HelloWorld\\Модель\\HelloWorld' не найден в /opt/bitnami/apps/magento/htdocs/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:93
Трассировка стека:
#0 /opt/bitnami/apps/magento/htdocs/vendor/magento/framework/ObjectManager/Factory/Compiled.php (88): Magento\\Framework\\ObjectManager\\Фабрика\\Абстрактный завод->Создать объект ('Шифталока\\Привет...', Массив)
# 1 /opt/bitnami/apps/magento/htdocs/vendor/magento/framework/ObjectManager/ObjectManager.php (57): Magento\\Framework\\ObjectManager\\Фабрика\\Скомпилированный->создать ('Шифталока\\Привет...', Массив)
# 2 /opt/bitnami/apps/magento/htdocs/var/generation/Ciptaloka/HelloWorld/Model/HelloWorldFactory.php (43): Magento\\Framework\\ObjectManager\\ObjectManager->создать ('Шифталока\\Привет...', Массив)
# 3 /opt/bitnami/apps/magento/htdocs/app/code/Ciptaloka/HelloWorld/Block/Catalog/Product/HelloWorld.php(75) : Ciptaloka\\Адский мир\\Модель\\helloworldfactory->создать()
#4 [внутренняя функция]: Шифталока\\Адский мир\\Блок\\Каталог\\P...
', ссылка:http://192.168.1.171/
Это структура каталогов моего пользовательского модуля:
app/code/Ciptaloka/HelloWorld/ ├── Block │ └── Catalog │ └── Product │ └── HelloWorld.php ├── etc │ ├── adminhtml │ │ ├── routes.xml │ │ └── system.xml │ ├── config.xml │ └── module.xml ├── Helper │ └── ConfigurationHelper.php ├── Model │ ├── HelloWorld.php │ ├── ResourceModel │ │ ├── HelloWorld │ │ │ └── Collection.php │ │ └── HelloWorld.php │ └── Source │ └── TextAlign.php ├── registration.php ├── Setup │ └── InstallSchema.php └── view └── frontend ├── layout │ └── catalog_product_view.xml ├── templates │ └── product │ └── hello.phtml └── web └── css └── hello.css
Как вы можете видеть в дереве dir, Ciptaloka\Адский мир\Модель\Адский мир действительно существует. И вот его содержимое в файле:
<?php
namespace Ciptloka\HelloWorld\Model;
use \Magento\Framework\Model\AbstractModel;
class HelloWorld extends AbstractModel
{
/**
* Model constructor
*/
protected function _construct()
{
$this->_init('Ciptaloka\HelloWorld\Model\ResourceModel\HelloWorld');
}
}
И другие файлы;
Model/ResourceModel/HelloWorld.php (Таблица ciptaloka_helloworld
является определено.):
<?php
namespace Ciptaloka\HelloWorld\Model\ResourceModel;
use \Magento\Framework\Model\ResourceModel\Db\AbstractDb;
class HelloWorld extends AbstractDb
{
/**
* Model initialization
*/
protected function _construct()
{
$this->_init('ciptaloka_helloworld', 'id');
}
}
Model/ResourceModel/HelloWorld/Collection.php:
<?php
namespace Ciptaloka\HelloWorld\Model\ResourceModel\HelloWorld;
use \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
class Collection extends AbstractCollection
{
/**
* Collection constructor
*/
protected function _construct()
{
$this->_init(
'Ciptaloka\HelloWorld\Model\HelloWorld',
'Ciptaloka\HelloWorld\Model\ResourceModel\HelloWorld'
);
}
}
Сгенерированная фабрика var/generation/Ciptaloka/HelloWorld/Model/HelloWorldFactory.php:
<?php
namespace Ciptaloka\HelloWorld\Model;
class HelloWorldFactory
{
protected $_objectManager = null;
protected $_instanceName = null;
public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager, $instanceName = 'Ciptaloka\\HelloWorld\\Model\\HelloWorld')
{
$this->_objectManager = $objectManager;
$this->_instanceName = $instanceName;
}
public function create(array $data = array())
{
return $this->_objectManager->create($this->_instanceName, $data);
}
}
И, файл блока:
<?php
namespace Ciptaloka\HelloWorld\Block\Catalog\Product;
use \Magento\Framework\View\Element\Template;
use \Magento\Framework\View\Element\Template\Context;
use \Ciptaloka\HelloWorld\Helper\ConfigurationHelper;
use \Ciptaloka\HelloWorld\Model\HelloWorldFactory;
class HelloWorld extends Template
{
/**
* @var ConfigurationHelper
*/
protected $_helper;
/**
* @var HelloWorldFactory
*/
protected $_helloWorldFactory;
public function __construct(
Context $context,
HelloWorldFactory $helloWorldFactory,
array $data = [],
ConfigurationHelper $helper
) {
parent::__construct($context, $data);
$this->_helloWorldFactory = $helloWorldFactory;
$this->_helper = $helper;
}
/**
* Returns 'Hello World!' string
*
* @return \Magento\Framework\Phrase
*/
public function getHelloWorldTxt()
{
return __('Hello World!');
}
public function getBlockLabel()
{
return $this->_helper->getBlockLabel();
}
public function getTextAlign()
{
return $this->_helper->getTextAlign();
}
protected function _toHtml()
{
if ($this->_helper->getEnable()) {
return parent::_toHtml();
}
else {
return '';
}
}
public function getCollection()
{
return $this->_helloWorldFactory->create()->getCollection();
}
}
Делаю ли я здесь какую-либо ошибку, которая вызвала эту ошибку? Любая помощь будет признательна.
1 answers
У вас есть опечатка в вашем app/code/Ciptaloka/HelloWorld/Model/HelloWorld.php
в line 3
:
namespace Ciptloka\HelloWorld\Model;
Это должно быть:
namespace Ciptaloka\HelloWorld\Model;
Обратите внимание на разницу между Ciptloka
и Ciptaloka
.