2013-04-10 55 views
4

我嘗試了Silex的例子,並把我的控制器放在一個單獨的目錄和類中。PHP 5.3.2的Silex問題?

否控制器方法將默認傳遞RequestApplication對象。這在我的開發機器上有效,它具有5.3.14,但不在默認的Ubuntu 5.3.2上。它給我:

PHP Catchable fatal error: Argument 1 passed to Sv\Controller\Index::index() must be an instance of Symfony\Component\HttpFoundation\Request, none given, called in /site/include/app/bootstrap.php on line 23 and defined in /site/include/app/Sv/Controller/Index.php on line 46

這裏是我的自舉PHP:

<?php 

require_once __DIR__ . '/../vendor/autoload.php'; 

use Sv\Repository\PostRepository; 
use Sv\Controller; 

$app = new Silex\Application(); 

// define global service for db access 
$app['posts.repository'] = $app->share(function() { 
    return new Sv\Repository\PostRepository; 
}); 

// register controller as a service 
$app->register(new Silex\Provider\ServiceControllerServiceProvider()); 
$app['default.controller'] = $app->share(function() use ($app) { 
    return new Controller\Index(); 
}); 
$app['service.controller'] = $app->share(function() use ($app) { 
    return new Controller\Service($app['posts.repository']); 
}); 

// define routes 
$app->get('/', 'default.controller:index'); 
$app->get('/next', 'default.controller:next'); 

$service = $app['controllers_factory']; 
$service->get('/', "service.controller:indexJsonAction"); 
// mount routes 
$app->mount('/service', $service); 

// definitions 
$app->run(); 

和這裏的控制器代碼:

namespace Sv\Controller; 

use Silex\Application; 
use Symfony\Component\HttpFoundation\Request; 

class Index 
{ 
    public function index(Request $request, Application $app) 
    { 
     return 'Route /index reached'; 
    } 

    public function next(Request $request, Application $app) 
    { 
     return 'Route /next reached'; 
    } 
} 

爲什麼這個不行?

我希望這不是阻止我PHP 5.3.2下使用ZF2同樣的問題...

+1

答案在於silex composer.json,要求部分:'「php」:「> = 5.3.3」' – 2013-04-10 16:58:39

+3

您正在運行一個37個月大的PHP版本! :)發佈2010年3月.. – Evert 2013-04-10 17:10:16

+0

@Evert嘗試更新Ubuntu 10.4到一個較新的版本,而無需自己編譯!想想在服務器上運行的應用程序噸非常聰明! – spankmaster79 2013-04-11 07:56:57

回答

6

Silex的需要PHP 5.3.3,你可以在their composer.json看到:

"require": { 
    "php": ">=5.3.3", 
    ... 

而且它也是在README file說:

Silex works with PHP 5.3.3 or later.

這是由於這樣的事實,Symfony2中不再支持PHP 5.3.2。

+0

我假設你的意思是5.3.2 :) – Maerlyn 2013-04-10 21:00:07

+0

@Maerlyn是的,修復。謝謝! – 2013-04-10 21:00:38

+0

該死的......沒有看着他們的composer.json ......很明顯...... – spankmaster79 2013-04-11 07:23:49