Php Zend framework 2:如何从控制器访问模块配置值

Php Zend framework 2:如何从控制器访问模块配置值,php,zend-framework,Php,Zend Framework,在module.config.php文件中,我设置了“password\u has\u type”的值。在控制器中,我想访问它。这是我的module.config.php文件: 'auth' => array( 'password_hash_type' => 'sha512', ), 'di' => array( 'instance' => array( 'alias' => array( 'auth' =&g

在module.config.php文件中,我设置了“password\u has\u type”的值。在控制器中,我想访问它。这是我的module.config.php文件:

'auth' => array(
    'password_hash_type' => 'sha512',
),
'di' => array(
    'instance' => array(
        'alias' => array(
            'auth' => 'Auth\Controller\AuthController',
            'auth_login_form' => 'Auth\Form\LoginForm',
        ),...
控制器中
,我使用了

use Auth\Module
Action
方法中,我尝试通过

echo Module::getOption('password_hash_type');
但我不能得到任何价值


那么有谁能帮我得到这个值吗

您可以借助别名和参数来完成此操作。将其放入
di->instance
数组:

'Auth\Controller\AuthController' => array(
    'parameters' => array(
        'passwordHashType' => 'sha512'
    )
),
它是您的控制器:

namespace Auth\Controller;
use Zend\Mvc\Controller\ActionController;

class AuthController extends ActionController
{
    protected $passwordHashType;

    public function indexAction()
    {
        echo $this->passwordHashType;
    }

    public function setPasswordHashType($passwordHashType)
    {
        $this->passwordHashType = $passwordHashType;
        return $this;
    }
}
请看我的答案

但为了使你的问题更具体,你可以这样做:

$config = $this->getServiceLocator()->get('Config');
$pwht = $config['auth']['password_hash_type'];

我希望这有帮助

如何
$auth=Module::getOption('auth');echo$auth['password\u hash\u type']?或在注册表中设置数组并将其置于任何位置