Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在PHP5.3之后, 打开yaf.use_namespace的情况下, 也可以使用 Yaf\Config_Simple? #280

Closed
xiuchanghu opened this issue May 11, 2016 · 1 comment

Comments

@xiuchanghu
Copy link

我yaf配置如下
[yaf]
extension=yaf.so
yaf.cache_config=1
yaf.use_namespace=1
根据文档看到
在PHP5.3之后, 打开yaf.use_namespace的情况下, 也可以使用 Yaf\Config_Simple
可是使用时报错
`<?php

use Yaf\Application;
use Yaf\Config_Simple;

/**

  • 对应用配置的封装,方便读取

  • Config::get('config')
    */
    class Config
    {
    private static $_config = null;
    public static function get($key = null, $default = null)
    {
    if ($value = self::getConfig()->get($key)) {
    return is_object($value) ? $value->toArray() : $value;
    } else {
    return $default;
    }
    }

    public static function set($key, $value)
    {
    return self::getConfig()->set($key, $value);
    }

    public static function getSecret($name = '', $key = null)
    {
    if ($path = self::getConfig()->get('secret_config_path')) {
    $secretConfig = new Yaf_Config_Ini($path, $name);
    return $key ? $secretConfig->get($key) : $secretConfig->toArray();
    }
    }

    /获取配置/
    private static function getConfig()
    {
    if (null === self::$_config) {
    $config = Application::app()->getConfig()->toArray();
    self::$_config = new Config_Simple($config, false);
    }
    return self::$_config;
    }
    }
    `

Warning: Yaf\Loader::autoload(): You should not use 'Yaf_' as class name prefix in /app/data/application/library/Config.php on line 67
Warning: Yaf\Loader::autoload(): Failed opening script /app/data/application/library/Yaf/Config/Simple.php: No such file or directory in /app/data/application/library/Config.php on line 67

Fatal error: Uncaught Error: Class 'Yaf\Config_Simple' not found in /app/data/application/library/Config.php:67 Stack trace: #0 /app/data/application/library/Config.php(24): Config::getConfig() #1 /app/data/application/library/Log.php(37): Config::get('log.dir') #2 /app/data/application/library/Log.php(20): Log::getStream('INFO') #3 /app/data/application/controllers/Index.php(28): Log::write('log\xE6\xB5\x8B\xE8\xAF\x95', 'INFO') #4 [internal function]: IndexController->indexAction() #5 /app/data/index.php(7): Yaf\Application->run() #6 {main} thrown in /app/data/application/library/Config.php on line 67

@lovelock
Copy link

lovelock commented Aug 7, 2016

完全看不懂这些代码。你是不是改完没有重启php-fpm?

@laruence laruence closed this as completed Mar 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants