在Symfony3.4中,我将<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
放在twig文件中,并更改PC版本页面以支持csrf_token。
当我对SP版本做同样的操作时,出现了以下错误。
你知道吗?
我删除了var/cache,但它没有意义。此外,getshopFooterMenu似乎没有在其他文件中使用。
误差
Attempted to call an undefined method named "getshopFooterMenu" of class
"__TwigTemplate_7a3846503e3cf029b2c0fa468b91304993e1ffe3af6967143083bc2ba5fa5e78".
in var/cache/dev/twig/a4/a482643be5a0726f762be6344916ca57425b8abc244bf4586931d6dc51604032.php (line 204)
SP_login.html.twig
<article>
<div class="login">
<h3>ABAHOUSE<br>Shop portal store management</h3>
<div class="content-padded">
<form method="post" action="{{ path('app_ahi_sp_admin_sp_security_logincheck') }}" autocomplete="off" >
{# Add #}
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
<span style="text-align:center;color:red;">{{ alertError | nl2br }}</span>
<input type="text" id="username" name="_username" class="imeOff" value="{{ last_username }}" placeholder="ID">
<input type="password" id="password" name="_password" placeholder="PASSWORD">
<button type="submit" class="btn btn-primary">Login</button>
</form>
</div>
</div>
</article>
PC_login.html.twig
<form method="post" action="{{ path('app_ahi_sp_admin_security_logincheck') }}" autocomplete="off" >
{# TODO I'll fix it later #}
<table style="margin: 20px auto">
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
<tr>
<td colspan="2" style="text-align:center;color:red;">{{ alertError | nl2br }}</td>
</tr>
<tr>
<td><label>Login ID</label></td>
<td><input type="text" id="username" name="_username" class="imeOff" value="{{ last_username }}"></td>
</tr>
<tr>
<td><label>password</label></td>
<td><input type="password" id="password" name="_password"></td>
</tr>
<tr>
<td colspan="2" style="text-align:center"><button type="submit" class="btn"><i class="icon-signin"></i> Login</button></td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<a href="{{ path("app_ahi_sp_admin_security_passwordforgot") }}">※If you forget your password</a>
</td>
</tr>
</table>
Twig_extension1
public function getshopFooterMenu()
{
$context = $this->env->getGlobals();
$blocks = array();
ob_start();
try {
// line 301
echo " <!-- ftMenu -->
<nav id="gNavi" class="bar bar-tab">
<a class="tab-item active" href="";
// line 303
echo $this->env->getExtension('routing')->getPath("ahi_sp_admin_sp_shop_default_index");
echo "" data-ignore="push">
<span class="icon icon-home"></span><span class="tab-label">Home</span>
</a>
<a href="#" id="postBtn" class="tab-item" data-trigger="modal" data-target="#modal-entryList" data-ignore="push">
<span class="icon icon-compose"></span><span class="tab-label">投稿</span>
</a>
<a href="#" id="searchBtn" class="tab-item" data-trigger="modal" data-target="#modal-searchList" data-ignore="push">
<span class="icon icon-search"></span><span class="tab-label">検索</span>
</a>
<a class="tab-item" href="";
// line 312
echo $this->env->getExtension('routing')->getPath("ahi_sp_admin_sp_security_logout");
echo "" data-ignore="push">
<span class="icon icon-close"></span><span class="tab-label">ログアウト</span>
</a>
</nav>
<!-- /ftMenu -->
";
} catch (Exception $e) {
ob_end_clean();
throw $e;
}
return ('' === $tmp = ob_get_clean()) ? '' : new Twig_Markup($tmp, $this->env->getCharset());
}
a482643be5a0726f762be6344916ca57425b8abc244bf4586931d6dc51604032.php
public function block_body($context, array $blocks = array())
{
// line 28
echo " <header class="bar bar-nav am">
";
// line 29
$this->displayBlock("BackIcon", $context, $blocks);
echo "
<h1 class="title">";
// line 30
$this->displayBlock("contentTitleIcon", $context, $blocks);
$this->displayBlock("contentTitle", $context, $blocks);
echo "</h1>
";
// line 31
$this->displayBlock("contentBackIcon", $context, $blocks);
echo "
";
// line 33
echo " ";
if ((!(isset($context["modal"]) ? $context["modal"] : null))) {
// line 34
echo " <button class="btn btn-link btn-nav pull-right info-btn " id="information-btn" data-target="#modal-info" data-trigger="modal" style="display:none">
<span class="icon icon-info"></span>
</button>
";
}
// line 38
echo " ";
// line 39
echo " ";
$this->displayBlock("modalCloseIcon", $context, $blocks);
echo "
</header>
";
// line 42
if ((!(isset($context["modal"]) ? $context["modal"] : null))) {
// line 43
echo "
";
// line 45
echo " ";
echo $context["macros"]->getshopFooterMenu();
echo "
";
// line 48
echo " ";
echo $context["macros"]->getarticleEntryList();
echo "
";
// line 51
echo " ";
echo $this->env->getExtension('http_kernel')->renderFragment($this->env->getExtension('http_kernel')->controller("AhiSpAdminBundle:Sp/Shop/Default:notification"));
echo "
";
// line 54, Error code
echo " ";
echo $context["macros"]->getarticleSearchList();
echo "
";
}
// line 56
echo "
";
// line 57
$this->displayBlock('contentBody', $context, $blocks);
// line 58
echo "
";
宏的导入目标为PC版本,但必须正确导入SP版本。前{- import 'AppAhiSpAdminBundle::adminmacros.html.twig' as macros -%}
在{- import 'AppAhiSpAdminBundle:Sp:adminmacros.html.twig' as macros -%}