Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
teebbstudios
teebblog
提交
65ddd5e2
T
teebblog
项目概览
teebbstudios
/
teebblog
通知
0
Star
5
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
teebblog
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
65ddd5e2
编写于
7月 24, 2021
作者:
伟
伟伟权
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
94. BaseController use translator service
上级
2dd91881
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
36 addition
and
5 deletion
+36
-5
src/Controller/BaseController.php
src/Controller/BaseController.php
+25
-0
src/Controller/CommentController.php
src/Controller/CommentController.php
+3
-2
src/Controller/PostController.php
src/Controller/PostController.php
+6
-2
translations/messages.zh_CN.yaml
translations/messages.zh_CN.yaml
+2
-1
未找到文件。
src/Controller/BaseController.php
0 → 100644
浏览文件 @
65ddd5e2
<?php
namespace
App\Controller
;
use
Symfony\Bundle\FrameworkBundle\Controller\AbstractController
;
use
Symfony\Contracts\Translation\TranslatorInterface
;
class
BaseController
extends
AbstractController
{
public
function
addFlashMessages
(
string
$type
,
$message
,
$parameters
=
[],
$domain
=
null
,
$locale
=
null
)
{
// dd($this->container);
$translator
=
$this
->
container
->
get
(
'translator'
);
$this
->
addFlash
(
$type
,
$translator
->
trans
(
$message
,
$parameters
,
$domain
,
$locale
));
}
public
static
function
getSubscribedServices
()
{
return
array_merge
(
parent
::
getSubscribedServices
(),
[
'translator'
=>
'?'
.
TranslatorInterface
::
class
]);
}
}
\ No newline at end of file
src/Controller/CommentController.php
浏览文件 @
65ddd5e2
...
...
@@ -14,7 +14,7 @@ use Symfony\Component\HttpFoundation\Request;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\Routing\Annotation\Route
;
class
CommentController
extends
Abstract
Controller
class
CommentController
extends
Base
Controller
{
#[
Route
(
'/post/{post_id}/comment/{comment_id}/reply'
,
options
:
[
'expose'
=>
true
],
name
:
'reply_comment'
),
...
...
@@ -66,7 +66,8 @@ class CommentController extends AbstractController
$em
->
persist
(
$data
);
$em
->
flush
();
$this
->
addFlash
(
'success'
,
'您的评论已成功提交!'
);
// $this->addFlash('success', '您的评论已成功提交!');
$this
->
addFlashMessages
(
'success'
,
'comment_submit_message'
);
return
$this
->
redirectToRoute
(
'post_show'
,
[
'id1'
=>
$post
->
getId
()]);
}
...
...
src/Controller/PostController.php
浏览文件 @
65ddd5e2
...
...
@@ -20,9 +20,10 @@ use Symfony\Component\HttpFoundation\Request;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\Routing\Annotation\Route
;
use
Symfony\Component\Security\Core\Security
;
use
Symfony\Contracts\Translation\TranslatorInterface
;
class
PostController
extends
Abstract
Controller
class
PostController
extends
Base
Controller
{
#[Route('/', name: 'post_index', methods: ['GET'])]
public
function
index
(
Request
$request
,
PostRepository
$postRepository
,
Security
$security
):
Response
...
...
@@ -47,6 +48,7 @@ class PostController extends AbstractController
#[ParamConverter('post', options: ['id' => 'id1'])]
public
function
show
(
Request
$request
,
Post
$post
,
EntityManagerInterface
$entityManager
,
PaginatorInterface
$paginator
,
CommentRepository
$commentRepository
,
TranslatorInterface
$translator
,
EventDispatcherInterface
$eventDispatcher
):
Response
{
$commentForm
=
$this
->
createForm
(
CommentType
::
class
);
...
...
@@ -88,9 +90,11 @@ class PostController extends AbstractController
$data
->
setPost
(
$post
);
$entityManager
->
persist
(
$data
);
$entityManager
->
flush
();
$this
->
addFlashMessages
(
'success'
,
'comment_submit_message'
,[
'%name%'
=>
$data
->
getAuthor
()]);
// $this->addFlash('success', $translator->trans('comment_submit_message'));
}
$this
->
addFlash
(
'success'
,
'您的评论已成功提交!'
);
}
$query
=
$commentRepository
->
getPaginationQuery
(
$post
);
...
...
translations/messages.zh_CN.yaml
浏览文件 @
65ddd5e2
Post
:
'
文章'
ID
:
'
ID'
Title
:
'
标题'
\ No newline at end of file
Title
:
'
标题'
comment_submit_message
:
'
%name%,
您的评论已提交。'
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录