Questions tagged «page-controller»

1
在控制器中调用服务的正确方法
我是服务(以及drupal 8!)的新手,正在尝试弄清楚服务。我认为也许我只是在以过时的方式进行创建。我想要做的是使“ hello generator”成为服务,并使用以下命令在另一个控制器中调用它: DBController.php namespace Drupal\db\Controller; use Drupal\Core\Controller\ControllerBase; use Drupal\db\DbServices\HelloGenerator; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Response; class DBController extends ControllerBase { private $helloGenerator; public function __construct(HelloGenerator $x) { $this->helloGenerator = $x; } public function say($count) { $hello = $this->helloGenerator->getHello($count); return new Response($hello); } public static function create(ContainerInterface $container) { $x = …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.