2013-04-10 44 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