我通过学说从数据库中获取一些结果.
结果数组例如ads.attraction包含内部逗号的字符串(单词).
如何将每个单词与逗号分开并在其自己的行上显示每个单词?
下面是我的目录结构.Views文件夹有一个子文件夹Default,里面有一个home.html.twig模板,这个模板是由一个方法呈现的DefaultController.虽然base.html.twig在views文件夹中.
|--views
|----Default
|------home.html.twig
|----base.html.twig
Run Code Online (Sandbox Code Playgroud)
base.html.twig的代码
<!DOCTYPE html>
<html>
<body>
<h1>testing</h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
home.html.twig的代码
{% extends '::base.html.twig' %}
Run Code Online (Sandbox Code Playgroud)
作为home.html.twig扩展base.html.twig因此home.html.twig必须证明<h1>testing</h1>,但它没有显示.
如何在成功授权后返回json对象而不是重定向到默认路径?我正在使用Symfony 3.0.1,我不使用FOSBundle.
我的登录控制器如下所示:
class ClientLoginController extends Controller
{
/**
* @Route("/login", name="login")
*/
public function loginAction(Request $request)
{
$client = new Client();
$form = $this->createForm(ClientLoginType::class, $client);
$form->handleRequest($request);
$authenticationUtils = $this->get('security.authentication_utils');
$lastEmail = $authenticationUtils->getLastUsername();
$error = $authenticationUtils->getLastAuthenticationError();
if ($form->isSubmitted() && $form->isValid())
{
return new JsonResponse(
array(
'message' => 'Success! You're authorised!',
'result' => $this->renderView('SymfonyBundle::client/success.html.twig')
), 200);
}
return $this->render(
'SymfonyBundle::security/security.html.twig',
array(
'login_form' => $form->createView(),
'error' => $error,
'last_email' => $lastEmail,
)
);
}
}
Run Code Online (Sandbox Code Playgroud)
而security.yml配置中的登录部分如下所示:
form_login:
login_path: login
check_path: login
username_parameter: …Run Code Online (Sandbox Code Playgroud)