Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从Codeigniter中的库访问控制器中声明的静态变量?_Php_Codeigniter_Codeigniter 3_Static Variables - Fatal编程技术网

Php 如何从Codeigniter中的库访问控制器中声明的静态变量?

Php 如何从Codeigniter中的库访问控制器中声明的静态变量?,php,codeigniter,codeigniter-3,static-variables,Php,Codeigniter,Codeigniter 3,Static Variables,我想访问Codeigniter控制器中声明的静态变量,并在库中使用它。这是代码 控制器位置和名称: 名称:控制台 位置:/application/controllers/Console.php class Console extends CI_Controller { public static $access_agents = [ '2017_app_v1.0', '2017_api_v1.0' ]; public static $d

我想访问Codeigniter控制器中声明的静态变量,并在库中使用它。这是代码

控制器位置和名称:

名称:
控制台

位置:
/application/controllers/Console.php

class Console extends CI_Controller {

    public static $access_agents = [
        '2017_app_v1.0',
        '2017_api_v1.0'
    ];

    public static $developer_secret = [
        'HTTP_X_DEVELOPER_SECRET' => 'XYZ'
    ];

}
class Api
{

    public static $CI;

    public function __construct()
    {
        self::$CI = & get_instance();
    }

    public static function print_services_list($list)
    {
        if(self::get_custom_header(##### CALL_STATIC_VARIABLE_HERE ######))
        $array = [
            'status' => '200',
            'message' => 'OK',
            'text' => "List of APIs under this Interface gateway.",
            'data' => $list
        ];
        self::print_json_array($array);
    }
}
库位置和名称:

名称:
Api

位置:
/applications/libraries/Api.php

class Console extends CI_Controller {

    public static $access_agents = [
        '2017_app_v1.0',
        '2017_api_v1.0'
    ];

    public static $developer_secret = [
        'HTTP_X_DEVELOPER_SECRET' => 'XYZ'
    ];

}
class Api
{

    public static $CI;

    public function __construct()
    {
        self::$CI = & get_instance();
    }

    public static function print_services_list($list)
    {
        if(self::get_custom_header(##### CALL_STATIC_VARIABLE_HERE ######))
        $array = [
            'status' => '200',
            'message' => 'OK',
            'text' => "List of APIs under this Interface gateway.",
            'data' => $list
        ];
        self::print_json_array($array);
    }
}

Console.php

class Console extends CI_Controller {

    public static $access_agents = [
        '2017_app_v1.0',
        '2017_api_v1.0'
    ];

    public static $developer_secret = [
        'HTTP_X_DEVELOPER_SECRET' => 'XYZ'
    ];

}
class Api
{

    public static $CI;

    public function __construct()
    {
        self::$CI = & get_instance();
    }

    public static function print_services_list($list)
    {
        if(self::get_custom_header(##### CALL_STATIC_VARIABLE_HERE ######))
        $array = [
            'status' => '200',
            'message' => 'OK',
            'text' => "List of APIs under this Interface gateway.",
            'data' => $list
        ];
        self::print_json_array($array);
    }
}

Api.php

class Console extends CI_Controller {

    public static $access_agents = [
        '2017_app_v1.0',
        '2017_api_v1.0'
    ];

    public static $developer_secret = [
        'HTTP_X_DEVELOPER_SECRET' => 'XYZ'
    ];

}
class Api
{

    public static $CI;

    public function __construct()
    {
        self::$CI = & get_instance();
    }

    public static function print_services_list($list)
    {
        if(self::get_custom_header(##### CALL_STATIC_VARIABLE_HERE ######))
        $array = [
            'status' => '200',
            'message' => 'OK',
            'text' => "List of APIs under this Interface gateway.",
            'data' => $list
        ];
        self::print_json_array($array);
    }
}
正如我所描述的,我想在这里访问控制台类中声明的静态变量,我在这里使用了
############

我曾经尝试过这样的事情:(我知道这可能行不通,我是对的)

控制台::$developer\u secret
-不工作

self::$CI->Console::$developer\u secret
-不工作


self::$CI->Console->$developer\u secret
-不工作

为什么不将这些变量放在配置文件中

application/config
文件夹中创建一个PHP文件。随便你怎么说都行。然后将变量放入文件中,如下所示

<?php
$config['static_var']['your-static-variable-name'] = 'Whatever value you want to initialize'

现在,您可以随时随地使用
$myvar
。希望这能对你有所帮助。

我没有别的办法。我只是想知道如何访问它。我已经使用了一个没有添加任何行的解决方案。我想一定有办法做到我所描述的。顺便说一句,谢谢你的意见。