문제

I have a class called ApplicationDecorator, which inherits Application and adds some often used methods.

At the moment each controller action contains at the beginning a line like

$appDec = new ApplicationDecorator($app);

Is it possible to tell Silex to pass the instance as parameter to the action like it is done for Application and Request?

So it would look like the following:

public function switchAction(ApplicationDecorator $appDec, Request $request) {

I am already using Controllers in classes and want to inject an inherited class of Application.

You can use Request and Silex\Application type hints to get $request and $app injected.

At the moment only Request and Application are supported.
Is there any possibility to extend the possible values?

도움이 되었습니까?

해결책

You are looking for controllers in classes:

$app->get('/', 'Igorw\\Foo::bar');

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

namespace Igorw
{
  class Foo
  {
    public function bar(Request $request, Application $app)
    {
        ...
    }
  }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top