在 cakephp 3 中获取安全盐

问题描述 投票:0回答:2

我阅读了文档,但无法了解如何从

Security.salt
中的
app.php
获取
Cakephp 3
值。我正在尝试像这样得到它

$salt = Configure::read('Security.salt');

导入以下库

use Cake\Core\Configure;
use Cake\Core\Configure\Engine\PhpConfig;

请帮忙。

Cakephp version is 3.4

php cakephp cakephp-3.4
2个回答
11
投票

Configure::Read('Security.salt')
在 cakephp 3 版本工作之前,将在 cakephp 3.x 中返回空白值。

为了从配置文件中读取盐,您需要包含安全命名空间:

use Cake\Utility\Security;

您可以使用以下方法检索盐的值:

Security::salt()

示例-

 echo Security::salt(); 

0
投票
// Security::salt() is deprecated as of 3.5.0 Use getSalt()/setSalt() instead.
<?php
use Cake\Utility\Security;

function yourMethod() {
    echo Security::getSalt();
}
© www.soinside.com 2019 - 2024. All rights reserved.