我有此配置文件:
error_reporting(E_ALL);
ini_set("display_errors", 1);
ini_set('session.cookie_httponly', 1); //This line 4 and error Line
和此配置加载程序:
namespace App\Core;
class Config
{
// this is public to allow better Unit Testing
public static $config;
public static function get($key)
{
if (!self::$config) {
$config_file = '../application/config/config.' . Environment::get() . '.php';
if (!file_exists($config_file)) {
return false;
}
self::$config = require $config_file;
}
return self::$config[$key];
}
}
还有这个controller.php
:
namespace App\Core;
/**
* This is the "base controller class". All other "real" controllers extend this class.
* Whenever a controller is created, we also
* 1. initialize a session
*/
class Controller
{
public $templates;
public function __construct()
{
// always initialize a session
Session::init();
Auth::checkSessionConcurrency();
$this->templates = new \League\Plates\Engine(Config::get('PATH_VIEW'));
$this->db = new DB(Config::get('DB_TYPE'), Config::get('DB_HOST'), Config::get('DB_USER'), Config::get('DB_PASS'), Config::get('DB_NAME'), Config::get('DB_PORT'));
}
}
现在有了索引控制器:
namespace App\Front\Controller;
use App\Front\Model\NoteModel;
use App\Core\Config;
class IndexController extends \App\Core\Controller
{
/**
* Construct this object by extending the basic Controller class
*/
public function __construct()
{
parent::__construct();
}
public function index()
{
echo $this->templates->render('index/index', [NoteModel::getAllNotes()]);
}
}
现在正在使用(PHP 7.2),我看到此错误:
警告:ini_set():会话处于活动状态。您目前无法在第4行的C:\ xampp \ htdocs \ cms \ application \ config \ config.development.php中更改会话模块的ini设置
我知道:在php> 7中启动会话后无法放置ini_set
:
我的修正:
我使用控制器,并将移动这两行移至Controller.php中Session::init();
之前:
$this->templates = new \League\Plates\Engine(Config::get('PATH_VIEW'));
$this->db = new DB(Config::get('DB_TYPE'), Config::get('DB_HOST'), Config::get('DB_USER'), Config::get('DB_PASS'), Config::get('DB_NAME'), Config::get('DB_PORT'));
并在操作中未看到/显示错误。有什么问题,我的FIX(在会话之前将代码移动到会话中)是真的吗? 感谢您的帮助。