ioioioioioioi
V2EX  ›  问与答

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

  •  
  •   ioioioioioioi · Dec 31, 2016 · 1607 views
    This topic created in 3511 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   ·   4099 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 05:32 · PVG 13:32 · LAX 22:32 · JFK 01:32
    ♥ Do have faith in what you're doing.