@Antoine553 please show your block file full code.
can you please write all code again and error msg?
<?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.
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
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
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"; } }
It work thanks you very much