我阅读了文档,但无法理解如何从app.php
中获取Cakephp 3
中的Security.salt
值。我尝试这样获取:
$salt = Configure::read('Security.salt');
导入以下库
use Cake\Core\Configure;
use Cake\Core\Configure\Engine\PhpConfig;
请帮忙。
Cakephp 版本为 3.4
我阅读了文档,但无法理解如何从app.php
中获取Cakephp 3
中的Security.salt
值。我尝试这样获取:
$salt = Configure::read('Security.salt');
导入以下库
use Cake\Core\Configure;
use Cake\Core\Configure\Engine\PhpConfig;
请帮忙。
Cakephp 版本为 3.4
Configure::Read('Security.salt')
在cakephp 3.x中会返回一个空值,在cakephp 3版本之前是有效的。
要从配置文件中读取salt,您需要包括Security名称空间:
use Cake\Utility\Security;
您可以使用以下方式检索盐的值:
Security::salt()
例子-
echo Security::salt();
// Security::salt() is deprecated as of 3.5.0 Use getSalt()/setSalt() instead.
<?php
use Cake\Utility\Security;
function yourMethod() {
echo Security::getSalt();
}