Magento – Magento2 How to pass argument parameters with multiple class

custom-themedimagento2

How to pass argument Parameter configuration inheritance in using theme module inside di.xml

here one thing in our theme inside header file inside define code below

<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); ?>
<?php $customerSession = $objectManager->create('Magento\Customer\Model\Session'); ?>
<?php $customerUrl = $objectManager->create('Magento\Customer\Model\Url'); ?>

here is one for this argument inside pass it "Magento\Customer\Model\Session" and second is "Magento\Customer\Model\Url" so after pass to argument inside how to define in constructor inside and call to phtml inside if any idea reply me
but i need to not used object manager through customer url and session get

Best Answer

Magento builds an array with elements corresponding to the items and passes it as the argument. The array can contain an infinite number of items, and each array item can be of any object type including an array itself.

When Magento merges the configuration files for a given scope, array arguments with the same name get merged into a new array.

When Magento loads a new configuration at a later time, either by a more specific scope or through code, then any array definitions in the new configuration will replace the loaded config instead of merging.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Example\Type">
        <arguments>
            <!-- Pass simple string -->
            <argument name="stringParam" xsi:type="string">someStringValue</argument>
            <!-- Pass instance of Magento\Some\Type -->
            <argument name="instanceParam" xsi:type="object">Magento\Some\Type</argument>
            <!-- Pass true -->
            <argument name="boolParam" xsi:type="boolean">1</argument>
            <!-- Pass 1 -->
            <argument name="intParam" xsi:type="number">1</argument>
            <!-- Pass application init argument, named by constant value -->
            <argument name="globalInitParam" xsi:type="init_parameter">Magento\Some\Class::SOME_CONSTANT</argument>
            <!-- Pass constant value -->
            <argument name="constantParam" xsi:type="const">Magento\Some\Class::SOME_CONSTANT</argument>
            <!-- Pass null value -->
            <argument name="optionalParam" xsi:type="null"/>
            <!-- Pass array -->
            <argument name="arrayParam" xsi:type="array">
                <!-- First element is value of constant -->
                <item name="firstElem" xsi:type="const">Magento\Some\Class::SOME_CONSTANT</item>
                <!-- Second element is null -->
                <item name="secondElem" xsi:type="null"/>
                <!-- Third element is a subarray -->
                <item name="thirdElem" xsi:type="array">
                    <!-- Subarray contains scalar value -->
                    <item name="scalarValue" xsi:type="string">ScalarValue</item>
                    <!-- and application init argument -->
                    <item name="globalArgument " xsi:type="init_parameter">Magento\Some\Class::SOME_CONSTANT</item>
                </item>
            </argument>
        </arguments>
    </type>
</config>

Reference: https://devdocs.magento.com/guides/v2.3/extension-dev-guide/build/di-xml-file.html

I hope this will help

Related Topic