2012-12-25 81 views
2

https://github.com/bcosca/fatfree#routing-engine繼起無脂肪框架示例代碼無脂肪框架中缺失的參數1 {關閉}()

$f3=require('lib/base.php'); 

    $f3->route('GET /brew/@count', 
     function($f3) { 
      echo $f3->get('PARAMS.count').' bottles of beer on the wall.'; 
     } 
    ); 
    $f3->run(); 

這一點,而我在我的瀏覽器中得到這個錯誤:

Internal Server Error 

    Missing argument 1 for {closure}() 

    * /var/www/f3/index.php:36 Base->{closure} 
    * /var/www/f3/lib/base.php:972   
    * Base->call(Closure::__set_state(),NULL,'beforeroute,afterroute') 
    * /var/www/f3/index.php:40 Base->run() 

我知道問題是$ f3沒有被傳遞到函數作爲參數,但我不明白爲什麼。有誰能夠幫助我?

回答

2

我只是一樣的情況!我使用的是SourceForge的3.0.1版本。我嘗試以下,這工作,但產生的其他問題:

$f3=require('lib/base.php'); 

$f3->route('GET /brew/@count', 
    function() use ($f3) { 
     echo $f3->get('PARAMS.count').' bottles of beer on the wall.'; 
    } 
); 
$f3->run(); 

使用條款(這不是在PHP很好的記錄),可以使用從父範圍變量從一個匿名函數。在這裏閱讀更多:Closure vs Anonymous function (difference?)

嘗試將F3內核升級到最新版本。其中一位開發人員建議從這裏升級到3.0.2版本:https://github.com/bcosca/fatfree。這是一個非常快速的修復!