mageplaza / magento-2-sample-module

Magento 2 Module development or Magento 2 Hello World Simple Module trends is increase rapidly while Magento release official version. That why we - Mageplaza - are wring about a topic that introduces how to create a simple Hello World module in Magento 2.
86 stars 104 forks source link

Errors during compilation #2

Open MurKit opened 7 years ago

MurKit commented 7 years ago

I'm on Magento CE 2.1.7.

After I download this extension and copy it to my Magento installation I run some cli commands.

sudo rm -rf var/di/ sudo rm -rf var/cache/ sudo rm -rf var/generation/ sudo rm -rf var/page_cache/

sudo chmod -R 777 pub/ sudo chmod -R 777 var/

php -f bin/magento cache:clean php bin/magento setup:upgrade php bin/magento setup:di:compile

And on the last step there are errors:

Errors during compilation:
    Mageplaza\HelloWorld\Controller\Adminhtml\Post\Save
        Incorrect dependency in class Mageplaza\HelloWorld\Controller\Adminhtml\Post\Save in /var/www/mage2/app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post/Save.php
\Magento\Backend\Model\Session already exists in context object
\Magento\Backend\Model\View\Result\RedirectFactory already exists in context object
    Mageplaza\HelloWorld\Controller\Adminhtml\Post\Edit
        Incorrect dependency in class Mageplaza\HelloWorld\Controller\Adminhtml\Post\Edit in /var/www/mage2/app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post/Edit.php
\Magento\Backend\Model\Session already exists in context object
\Magento\Backend\Model\View\Result\RedirectFactory already exists in context object
    Mageplaza\HelloWorld\Controller\Adminhtml\Post
        Incorrect dependency in class Mageplaza\HelloWorld\Controller\Adminhtml\Post in /var/www/mage2/app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post.php
\Magento\Backend\Model\View\Result\RedirectFactory already exists in context object
Total Errors Count: 3
Errors during compilation:
    Mageplaza\HelloWorld\Controller\Adminhtml\Post\Save
        Incorrect dependency in class Mageplaza\HelloWorld\Controller\Adminhtml\Post\Save in /var/www/mage2/app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post/Save.php
\Magento\Backend\Model\Session already exists in context object
\Magento\Backend\Model\View\Result\RedirectFactory already exists in context object
    Mageplaza\HelloWorld\Controller\Adminhtml\Post\Edit
        Incorrect dependency in class Mageplaza\HelloWorld\Controller\Adminhtml\Post\Edit in /var/www/mage2/app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post/Edit.php
\Magento\Backend\Model\Session already exists in context object
\Magento\Backend\Model\View\Result\RedirectFactory already exists in context object
    Mageplaza\HelloWorld\Controller\Adminhtml\Post
        Incorrect dependency in class Mageplaza\HelloWorld\Controller\Adminhtml\Post in /var/www/mage2/app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post.php
\Magento\Backend\Model\View\Result\RedirectFactory already exists in context object
Total Errors Count: 3
Errors during compilation:
    Mageplaza\HelloWorld\Controller\Adminhtml\Post\Save
        Incorrect dependency in class Mageplaza\HelloWorld\Controller\Adminhtml\Post\Save in /var/www/mage2/app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post/Save.php
\Magento\Backend\Model\Session already exists in context object
\Magento\Backend\Model\View\Result\RedirectFactory already exists in context object
    Mageplaza\HelloWorld\Controller\Adminhtml\Post\Edit
        Incorrect dependency in class Mageplaza\HelloWorld\Controller\Adminhtml\Post\Edit in /var/www/mage2/app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post/Edit.php
\Magento\Backend\Model\Session already exists in context object
\Magento\Backend\Model\View\Result\RedirectFactory already exists in context object
    Mageplaza\HelloWorld\Controller\Adminhtml\Post
        Incorrect dependency in class Mageplaza\HelloWorld\Controller\Adminhtml\Post in /var/www/mage2/app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post.php
\Magento\Backend\Model\View\Result\RedirectFactory already exists in context object
Total Errors Count: 3
Errors during compilation:
    Mageplaza\HelloWorld\Controller\Adminhtml\Post\Save
        Incorrect dependency in class Mageplaza\HelloWorld\Controller\Adminhtml\Post\Save in /var/www/mage2/app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post/Save.php
\Magento\Backend\Model\Session already exists in context object
\Magento\Backend\Model\View\Result\RedirectFactory already exists in context object
    Mageplaza\HelloWorld\Controller\Adminhtml\Post\Edit
        Incorrect dependency in class Mageplaza\HelloWorld\Controller\Adminhtml\Post\Edit in /var/www/mage2/app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post/Edit.php
\Magento\Backend\Model\Session already exists in context object
\Magento\Backend\Model\View\Result\RedirectFactory already exists in context object
    Mageplaza\HelloWorld\Controller\Adminhtml\Post
        Incorrect dependency in class Mageplaza\HelloWorld\Controller\Adminhtml\Post in /var/www/mage2/app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post.php
\Magento\Backend\Model\View\Result\RedirectFactory already exists in context object
Total Errors Count: 3
Errors during compilation:
    Mageplaza\HelloWorld\Controller\Adminhtml\Post\Save
        Incorrect dependency in class Mageplaza\HelloWorld\Controller\Adminhtml\Post\Save in /var/www/mage2/app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post/Save.php
\Magento\Backend\Model\Session already exists in context object
\Magento\Backend\Model\View\Result\RedirectFactory already exists in context object
    Mageplaza\HelloWorld\Controller\Adminhtml\Post\Edit
        Incorrect dependency in class Mageplaza\HelloWorld\Controller\Adminhtml\Post\Edit in /var/www/mage2/app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post/Edit.php
\Magento\Backend\Model\Session already exists in context object
\Magento\Backend\Model\View\Result\RedirectFactory already exists in context object
    Mageplaza\HelloWorld\Controller\Adminhtml\Post
        Incorrect dependency in class Mageplaza\HelloWorld\Controller\Adminhtml\Post in /var/www/mage2/app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post.php
\Magento\Backend\Model\View\Result\RedirectFactory already exists in context object
Total Errors Count: 3
Errors during compilation:
    Mageplaza\HelloWorld\Controller\Adminhtml\Post\Save
        Incorrect dependency in class Mageplaza\HelloWorld\Controller\Adminhtml\Post\Save in /var/www/mage2/app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post/Save.php
\Magento\Backend\Model\Session already exists in context object
\Magento\Backend\Model\View\Result\RedirectFactory already exists in context object
    Mageplaza\HelloWorld\Controller\Adminhtml\Post\Edit
        Incorrect dependency in class Mageplaza\HelloWorld\Controller\Adminhtml\Post\Edit in /var/www/mage2/app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post/Edit.php
\Magento\Backend\Model\Session already exists in context object
\Magento\Backend\Model\View\Result\RedirectFactory already exists in context object
    Mageplaza\HelloWorld\Controller\Adminhtml\Post
        Incorrect dependency in class Mageplaza\HelloWorld\Controller\Adminhtml\Post in /var/www/mage2/app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post.php
\Magento\Backend\Model\View\Result\RedirectFactory already exists in context object
Total Errors Count: 3
irinikp commented 7 years ago

I get the exact same error

NagarajuKasa commented 7 years ago

Yes I am also facing the same issues http://prntscr.com/g3ubke

tarungupta051 commented 6 years ago

Hello You need to below changes into files.

1) Incorrect dependency in class Mageplaza\HelloWorld\Controller\Adminhtml\Post in /var/www/mage2/app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post.php \Magento\Backend\Model\View\Result\RedirectFactory already exists in context object

Reply : $this->redirectFactory = $context->getRedirectFactory();

comment below code : //\Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory,

use below code :+1: public function __construct( \Mageplaza\HelloWorld\Model\Upload $uploadModel, \Mageplaza\HelloWorld\Model\Post\File $fileModel, \Mageplaza\HelloWorld\Model\Post\Image $imageModel, //\Magento\Backend\Model\Session $backendSession, \Mageplaza\HelloWorld\Model\PostFactory $postFactory, \Magento\Framework\Registry $registry, //\Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory, /// \Magento\Backend\Model\View\Result\RedirectFactory $redirectFactory , \Magento\Backend\App\Action\Context $context //Phpexcel_PHPExcel $xlsx //\PHPExcel\IOFactory $iOFactory; //Phpexcel_PHPExcel $xlsx

)
{
    $this->_uploadModel    = $uploadModel;
    $this->_fileModel      = $fileModel;
    $this->_imageModel     = $imageModel;
  //  $this->_backendSession = $backendSession;
    $this->redirectFactory =  $context->getRedirectFactory();
    //$this->_iOFactory = $iOFactory;
    //$this->excelFactory = $excelFactory;
    //$this->excelFactory = $excelFactory;
    parent::__construct($postFactory, $registry,$context);
}
tarungupta051 commented 6 years ago

Hello ,

1) Incorrect dependency in class Mageplaza\HelloWorld\Controller\Adminhtml\Post\Save in /var/www/mage2/app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post/Save.php \Magento\Backend\Model\Session already exists in context object \Magento\Backend\Model\View\Result\RedirectFactory already exists in context object Mageplaza\HelloWorld\Controller\Adminhtml\Post\Edit

Reply : use below code :+1: public function __construct( // \Magento\Backend\Model\Session $backendSession, \Magento\Framework\View\Result\PageFactory $resultPageFactory, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, \Mageplaza\HelloWorld\Model\PostFactory $postFactory, \Magento\Framework\Registry $registry, //\Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Backend\App\Action\Context $context ) { //$this->_backendSession = $backendSession; $this->_resultPageFactory = $resultPageFactory; $this->_resultJsonFactory = $resultJsonFactory; $this->redirectFactory = $context->getRedirectFactory(); parent::__construct($postFactory,$registry,$context); }