Answer the question
In order to leave comments, you need to log in
Silex DI for controller?
Hello.
Is it possible for the controller to accept an object of the Silex\Application class in the constructor?
Tried this approach
$app->get('/','AppComponents\Controllers\HelloController::index' );
// HelloController.php
namespace AppComponents\Controllers;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Silex;
use Silex\Application;
class HelloController{
protected $app;
function __construct(Application $app) {
$this->app = $app;
}
function index() {
return new Response("hello");
}
}
public function test(Application $app){
var_dump($app);
return "Bloody Hell!! Its working";
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question