获取数组中返回的另一个文件中的函数值

时间:2019-06-05 18:31:07

标签: function magento

我在文件中有一个函数,用于通知数组中的值,但我需要在另一个文件中获取这些值。

我正在使用magento,并且需要从具有发出请求的客户端名称的函数中获取信息,我试图获取first_name,但没有用。

FileOne.php

public function getCustomerInfo($customer, $order)
    {

        $email = htmlentities($customer->getEmail());
        if ($email == "") {
            $email = $order['customer_email'];
        }

        $first_name = htmlentities($customer->getFirstname());
        if ($first_name == "") {
            $first_name = $order->getBillingAddress()->getFirstname();
        }

        $last_name = htmlentities($customer->getLastname());
        if ($last_name == "") {
            $last_name = $order->getBillingAddress()->getLastname();
        }

        return array('email' => $email, 'first_name' => $first_name, 'last_name' => $last_name);
    }

文件Two.php

require(../Model/fileone.php

public function getName(){

            $name = $this->getCustomerInfo($customer, $order);
            $first_name = $name['first_name'];
            return $first_name;
    }

我需要显示在first_name中的客户端名称,但是没有显示。

1 个答案:

答案 0 :(得分:0)

您有两个文件,一个文件具有您要从另一个文件中调用的功能。

要从另一个文件使用getCustomerInfo()函数,您将需要导入包含该函数的类(使用userequire_once())。

如果导入另一个文件,则在函数调用之前引用该函数将不使用this->,因为getCustomerInfo()函数与getName()函数不在同一类中。

由于在您提供的示例中,这些函数不是类的一部分,因此您应该能够require_once(fileOne.php);位于fileTwo.php的顶部,并且可以在该文件中的任何位置调用getCustomerInfo()。 / p>

在调用getCustomerInfo()时,每个函数的声明都需要有两个参数。

相关问题