1234567891011121314151617181920212223242526272829303132333435 |
- <?php
- declare(strict_types=1);
- namespace App\Controller;
- use Hyperf\HttpServer\Annotation\AutoController;
- use Hyperf\HttpServer\Contract\ResponseInterface;
- use Hyperf\View\RenderInterface;
- use Hyperf\HttpServer\Annotation\Controller;
- use Hyperf\HttpServer\Annotation\GetMapping;
- use Hyperf\Utils\ApplicationContext;
- #[AutoController]
- class ViewController
- {
- protected RenderInterface $render;
- public function __construct(RenderInterface $render)
- {
- $this->render = $render;
- }
- public function index(ResponseInterface $response)
- {
- $render = ApplicationContext::getContainer()
- ->get(\Hyperf\View\RenderInterface::class);
- return $render->render('index', [
- 'title' => 'Smarty示例',
- 'message' => '欢迎使用Hyperf+Smarty',
- 'show_additional' => true,
- 'additional' => '这是通过Smarty渲染的内容'
- ]);
- }
- }
|