cancel
Showing results for 
Search instead for 
Did you mean: 

Load Multiple Class

SOLVED

Re: Load Multiple Class

@Antoine553 please show your block file full code.

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Load Multiple Class

@Antoine553 

 

can you please write all code again and error msg?


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Load Multiple Class

<?php
namespace Mymodule\AdminPage\Block\Adminhtml;

use Magento\Backend\Block\Template;

class Contactslist extends Template
{
  public function mycustom(){
      echo "test";
  }
}

 Please update with above code and check.

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Load Multiple Class

I have my Block

<?php
namespace Mymodule\Admin_Page\Block\Adminhtml;

use Magento\Backend\Block\Template;

class Contactslist extends \Magento\Backend\Block\Template
{
  public function mycustom(){
      echo "test";
  }
}

My layout

<?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">
        <head>
			<title>Module Mymodule</title>
        </head>
        <body>
            <referenceContainer name="content">
                <block class="Mymodule\AdminPage\Block\Adminhtml\Contactslist" template="Mymodule_AdminPage::nettoyage.phtml"/>
            </referenceContainer>
        </body>
    </page>

and this error message when i try it

 

PHP Fatal error:  Cannot redeclare class Mymodule\\Admin_Page\\Block\\Adminhtml\\Contactslist in /home/mademonstration/public_html/newmagento3/app/code/Mymodule/AdminPage/Block/Adminhtml/Contactslist.php on line 11

Re: Load Multiple Class

check namespace and xml block name

 

namespace Mymodule\Admin_Page\Block\Adminhtml;

in xml you write

Mymodule\AdminPage\Block\Adminhtml\Contactslist

 Clear difference Admin_Page and AdminPage


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Load Multiple Class

You have to keep below 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">
    <head>
  <title>Module Mymodule</title>
    </head>
    <body>
        <referenceContainer name="content">
            <block class="Mymodule\AdminPage\Block\Adminhtml\Contactslist" template="Mymodule_AdminPage::nettoyage.phtml"/>
        </referenceContainer>
    </body>
</page>

Now,

Block file,

<?php
namespace Mymodule\AdminPage\Block\Adminhtml;

use Magento\Backend\Block\Template;

class Contactslist extends Template
{
  public function mycustom(){
      echo "test";
  }
}
If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Load Multiple Class

It work thanks you very much