Php 从silex中的服务提供程序获取调用类/方法
如果我有以下代码,我将如何在提供程序中获取调用方法和类:Php 从silex中的服务提供程序获取调用类/方法,php,silex,Php,Silex,如果我有以下代码,我将如何在提供程序中获取调用方法和类: class HelloServiceProvider implements ServiceProviderInterface { public function register(Application $app){ $app['hello'] = $app->share(function () { // Get hello/indexAction }); }
class HelloServiceProvider implements ServiceProviderInterface {
public function register(Application $app){
$app['hello'] = $app->share(function () {
// Get hello/indexAction
});
}
public function boot(Application $app){}
}
class hello {
public function addAction(){
$app['hello']()
}
}
$app->get('/hello', 'hello.controller:indexAction');
这可能吗?谢谢确实可能,但您需要一些更改:
<?php
// file HelloServiceProvider.php
class HelloServiceProvider implements ServiceProviderInterface {
public function register(Application $app){
$app['hello'] = $app->share(function () {
// Get hello/indexAction
});
}
public function boot(Application $app){}
}
// file Hello.php
class Hello {
public function indexAction(Application $app){
$app['hello']()
}
}
// somewhere in your code:
$app->register(new Silex\Provider\ServiceControllerServiceProvider());
$app->register(new HelloServiceProvider());
$app['hello.controller'] = $app->share(function() {
return new hello();
});
$app->get('/hello', 'hello.controller:indexAction');
这是我的错,我没有包括我的一些代码,这有点愚蠢……我的代码工作正常,一切正常。我只是想弄清楚是否有办法获得调用函数的方法和类。在您的示例中,您添加了register函数,但没有显示如何在$app['hello']函数中获取调用类。我认为您可以,检查并也可以。啊,所以silex中没有内置任何内容?这将允许我获得方法/类?不,没有这样的原生Silex选项。