나는 Silex에서 예제를 시도하고 별도의 디렉토리와 클래스에 내 컨트롤러를 넣어.Silex PHP 5.3.2 관련 문제?
아니요 컨트롤러 메서드를 사용하면 Request
및 Application
개체가 기본적으로 전달됩니다. 이 5.3.14 있지만 기본 우분투 5.3.2있는 내 dev 컴퓨터에서 작동합니다. 그것은 줘 :
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
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';
}
}
왜이 작동하지 않는 이유는 무엇입니까?
나는 이것이 당신이 their composer.json
에서 볼 수
답은 silex composer.json, 요구 사항 섹션에 있습니다 : ""php ":"> = 5.3.3 " –
37 개월 된 PHP 버전을 실행 중입니다! :) 2010 년 3 월 출시 .. – Evert
@Evert 우분투 10.4를 직접 컴파일하지 않고 최신 버전으로 업데이트 해보세요! 그리고 서버에서 실행되는 t 응용 프로그램에 대해 생각 해보세요. 매우 똑똑합니다! – spankmaster79