摘自 Slim 框架文档:
mode
This is an identifier for the application’s current mode of operation. The mode does not affect a Slim application’s internal functionality. Instead, the mode is only for you to optionally invoke your own code for a given mode with the configMode() application method.
The application mode is declared during instantiation, either as an environment variable or as an argument to the Slim application constructor. It cannot be changed afterward. The mode may be anything you want — “development”, “test”, and “production” are typical, but you are free to use anything you want (e.g. “foo”).
<?php
$app = new \Slim\Slim(array(
'mode' => 'development'
));
?>
问题是,当我尝试调用 $app->configMode(); 时出现 fatal error ,指出 configMode() 方法未定义...
最佳答案
您可以通过调用 $app->getMode();
另一种方法是使用 configureMode() .
<?php
// Set the current mode
$app = new \Slim\Slim(array(
'mode' => 'production'
));
// Only invoked if mode is "production"
$app->configureMode('production', function () use ($app) {
$app->config(array(
'log.enable' => true,
'debug' => false
));
});
// Only invoked if mode is "development"
$app->configureMode('development', function () use ($app) {
$app->config(array(
'log.enable' => false,
'debug' => true
));
});
关于php - 如何在 slim 框架上获取环境模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15948250/