在Userfrosting

时间:2016-07-26 17:59:51

标签: slim userfrosting

我试图使用内置的Slim编写器,但到目前为止还没有成功。

这就是我正在尝试的,但我收到了错误。

  1. 更改为config_userfrosting.php:

    /*Create a log writer */
    
    $logWriter = new \UserFrosting\LogWriter(fopen('C:\xampp\htdocs\userfrosting\log\dev_logfile.log', 'a'));
    
    $app->configureMode('dev', function () use ($app, $public_path, $uri_public_root) {
    $app->config([
        'log.enable' => true,
        'log.writer' => $logWriter,
        'debug' => false,
    
  2. 从index.php调用日志编写器:

  3. $ app-> log-> debug("这是来自记录器的测试...");

    收到错误:

      PHP Notice:  Undefined variable: logWriter in \\userfrosting\\config-userfrosting.php on line 33
    

1 个答案:

答案 0 :(得分:2)

为了在闭包(configureMode)中访问变量,您需要使用use(...)参数列表传递它:

$app->configureMode('dev', function () use ($app, $public_path, $uri_public_root, $logWriter) {

    $app->config([
        'log.enable' => true,
        'log.writer' => $logWriter,
        'debug' => false,
        ...
});