ioioioioioioi
V2EX  ›  问与答

如何像 Laravel Database 一样,初始化 class 后,可以直接引用的,比如,写了一个 cache class

  •  
  •   ioioioioioioi · Dec 31, 2016 · 1608 views
    This topic created in 3514 days ago, the information mentioned may be changed or developed.
    # 定义并运行初始化函数
    function cacheInit()
    {
        $cache = new cache(env('memcached_host'), env('memcached_port'));
    
        $cache->setAsGlobal();
    }
    
    # 在任何位置,可以直接使用
    \cache::get($key);
    
    1 replies    2016-12-31 15:11:48 +08:00
    jessynt
        1
    jessynt  
       Dec 31, 2016
    自己实现一个服务容器即可,也可以看下 http://pimple.sensiolabs.org/
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1047 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:39 · PVG 02:39 · LAX 11:39 · JFK 14:39
    ♥ Do have faith in what you're doing.