0

I would like to know, I have a custom method in test.php at magento2 root folder i would like to call my custom method how to do that? i have written a sample test script below please suggest me here thanks.

    <?php
        use Magento\Framework\App\Bootstrap;
        require __DIR__ . '/app/bootstrap.php';
        $bootstrap = Bootstrap::create(BP, $_SERVER);
        $obj = $bootstrap->getObjectManager();
        $state = $obj->get('Magento\Framework\App\State');

        $state->setAreaCode('frontend');
        ini_set('display_errors', 1);

        //Here how to call my custom method ????        

        public function getCustomMethod($i)
        {        
         echo $i;          
         (or) 
         return $i;        
        }        
 ?>

1 Answer 1

1

Since you are not going to create any class in this php file, you can directly define and declare the method as like below.

<?php
    use Magento\Framework\App\Bootstrap;
    require __DIR__ . '/app/bootstrap.php';
    $bootstrap = Bootstrap::create(BP, $_SERVER);
    $obj = $bootstrap->getObjectManager();
    $state = $obj->get('Magento\Framework\App\State');

    $state->setAreaCode('frontend');
    ini_set('display_errors', 1);

    $i = "Hello";
    getCustomMethod($i);     

    function getCustomMethod($i)
    {        
     echo $i;          
     (or) 
     return $i;        
    } 
1
  • thanks for your reply @venkatesankrish let me check and get back to u Aug 1, 2017 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.