[英]Use variable from “public static function” in another “public static function”
I know this question is asked like a hundred times in hundred different ways. 我知道这个问题以一百种不同的方式被问了一百遍。 But I just can't get this particular one to work.
但是我无法让这个特殊的人工作。 I am really confused.
我真的很困惑。
This is the very beginning of my script: 这是我脚本的开始:
<?php
class API {
protected static $message, $data, $status, $session, $token, $dbo, $app;
const FAIL = 0;
const SUCCESS = 1;
const INCOMPLETE_ARGS = 2;
const GROUP_ALLOW = array(5);
public static function Init() {
global $app;
self::$status = false;
self::$message = "Invalid request.";
self::$data = "";
}
public static function Render() {
echo preg_replace("/\\\\u([0-9abcdef]{4})/", "&#x$1;", json_encode(array(
"status" => self::$status,
"message" => self::$message,
"data" => self::$data))
);
}
Then there is this function: 然后有这个功能:
public static function Login() {
$email = (isset($_REQUEST['email'])) ? $_REQUEST['email'] : "";
$password = (isset($_REQUEST['password'])) ? $_REQUEST['password'] : "";
require_once ("../app/Mage.php");
umask(0);
ob_start();
session_start();
Mage::app('default');
Mage::getSingleton("core/session", array("name" => "frontend"));
$b2bwebsiteid = Mage::getStoreConfig('base/general/b2bwebsite');
//$websiteId = Mage::app()->getWebsite()->getId();
//$store = Mage::app()->getStore();
$customer = Mage::getModel("customer/customer");
$customer->website_id = $b2bwebsiteid;
$customer->loadByEmail($email);
$countryCodeBE = $customer->getDefaultBillingAddress()->getCountry();
$countrybe = Mage::getModel('directory/country')->loadByCode($countryCodeBE);
$countryid = $countrybe->getCountryId();
.....
.....
And in between there is a lot more code and functions. 在两者之间还有更多的代码和功能。
Now a bit further, there is another function: 现在再进一步,还有另一个功能:
public static function ProductInfoNew() {
And now the thing I want, is to load the variable $countryid from that first function in the ProductInfoNew function so that I can do something like this: 现在我想要的是从ProductInfoNew函数中的第一个函数加载变量$ countryid ,以便我可以执行以下操作:
if ($countryid == "BE") {
$groupid = 6;
}
else {
$groupid = 4;
}
But the output always seems to be NULL or Empty. 但是输出似乎始终为NULL或Empty。
I tried setting the $countryid variable as global, static, tried to load the variable with self:: and I tried so many things but I can't get it to work. 我尝试将$ countryid变量设置为全局,静态,并尝试使用self ::加载该变量,并且尝试了很多事情,但无法正常工作。
Does anyone know the correct solution to do this? 有人知道正确的解决方案吗? Thanks a lot in advance.
非常感谢。
$countryid
should be a field inside of the class you are using. $countryid
应该是您正在使用的类中的一个字段。
class API {
private static $country_id;
public static function ProductInfoNew() {
if (self::$country_id == "BE") {
$groupid = 6;
} else {
$groupid = 4;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.