cancel
Showing results for 
Search instead for 
Did you mean: 

Load Multiple Class

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Load Multiple Class

 

I'm actually following the tutorial of Pierre Fay but i'm working on a page in the admin side but i don't get the correct way to put a second class "Mymodule\Admin_Page\Block\Contactlists" idea someone ?

<?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 Mymoodule</title>
        </head>
        <body>
            <referenceContainer name="content">
                <block class="Magento\Backend\Block\Template" template="Mymodule_AdminPage::nettoyage.phtml"/>
            </referenceContainer>
        </body>
    </page>

 

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

16 REPLIES 16

Re: Load Multiple Class

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

Now create your block class,

You can extend base class like this,

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

class Contactlists extends \Magento\Backend\Block\Template
{
  public function mycustom(){
      //your code
      return;
  }
}

Remove var/generation folder.

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

Re: Load Multiple Class

I tried but if i delete the :

class="Magento\Backend\Block\Template"

It no longer work probably because he need it in the admin side.

Re: Load Multiple Class

@Antoine553

 

in admin side you need to use Magento\Backend\Block\Template;

 

 


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

Re: Load Multiple Class

I have my block Contactslist

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

use Magento\Backend\Block\Template;

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

and 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>

but at the end i have a whithe page and the log tell me 

 

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

Re: Load Multiple Class

 

@Sunil Patel ok but how can i link new class if i'm force to keep it
 

Re: Load Multiple Class

@Antoine553 which is your line no. 12,

You can set class definataion in your block file like this,

 

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

use Magento\Backend\Block\Template;

class Contactslist extends Template
{
    public function test()
    {
        echo 'helloworld';
    }
}

 

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

Re: Load Multiple Class

@Antoine553

 

namespace is wrong 

it should be 

namespace Mymodule\AdminPage\Block\Adminhtml;

 


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

Re: Load Multiple Class

the line 12 is the last one with a "}"

 

i tried your code but it don't work

Re: Load Multiple Class

@Sunil Patel

i did it but nothing change

actually i have

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

use Magento\Backend\Block\Template;

class Contactslist extends \Magento\Backend\Block\Template
{
  public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        array $data = []
    ) {
        parent::__construct($context, $data);
    }

  public function mycustom(){
      echo "test";
  }
}