为什么 silex 不在构造函数中解析 App?
Why silex don't resolve App in consructor?
当我尝试在构造函数中使用自动解析依赖项时出现错误,尽管在方法中它工作正常。
<?php
namespace App\Controller;
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
class AuthorController
{
// Produce an error
// public $app;
// public $request;
// public $entityManager;
//
// public function __construct(Application $app, Request $request)
// {
// $this->app=$app;
// $this->request=$request;
// }
public function create(Application $app, Request $request)
{
}
}
Argument 1 passed to App\Controller\AuthorController::__construct() must be an instance of Silex\Application, none given
定义路由时必须将$app
作为参数传递给构造函数
$app->post(
'/author',
function (Request $request) use ($app) {
$controller = new AuthorController(
$app,
$request
);
return $controller->create();
}
);
当我尝试在构造函数中使用自动解析依赖项时出现错误,尽管在方法中它工作正常。
<?php
namespace App\Controller;
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
class AuthorController
{
// Produce an error
// public $app;
// public $request;
// public $entityManager;
//
// public function __construct(Application $app, Request $request)
// {
// $this->app=$app;
// $this->request=$request;
// }
public function create(Application $app, Request $request)
{
}
}
Argument 1 passed to App\Controller\AuthorController::__construct() must be an instance of Silex\Application, none given
定义路由时必须将$app
作为参数传递给构造函数
$app->post(
'/author',
function (Request $request) use ($app) {
$controller = new AuthorController(
$app,
$request
);
return $controller->create();
}
);