我有一个中间件目录包含3个类,即OldInputMiddleware,MiddleWare和ErrorsMiddleware:
class Middleware {
protected $container;
public function __construct($container){
$this->container = $container;
}
class OldInputMiddleware extends Middleware {
public function __invoke($request, $response, $next){
if (isset($_SESSION['errors'])) {
$this->container->view->getEnvironment()->addGlobal('old', $_SESSION['old']);
$_SESSION['old'] = $request->getParams();
}
//always return response with the next occurring
// request and response
$response = $next($request, $response);
return $response;
}
ErrorsMiddleware类似于我在OldInputMiddleware中所拥有的,但它在检索后取消了会话变量,并且在我的signup.twig文件中:
<div class="form-group {{ errors.email ? 'has-error' : '' }}">
<label for="email">Email</label>
<input type="text" name="email" id="email" placeholder="someone@domain.com" class="form-control" value="{{ old.email }}">
{% if errors.email %}
<span class="help-block">{{ errors.email | first }}</span>
{% endif %}
错误中间件工作正常并返回相关的错误消息,但当我尝试通过在值属性中添加twig注释来预先处理旧数据时,数据无法检索。
答案 0 :(得分:0)
回答自己,这句话是一个愚蠢的错误:
if (isset($_SESSION['errors']))
应该是$ _SESSION ['old']而不是$ _SESSION ['errors']
答案 1 :(得分:0)
您可以删除if语句。没必要。
您可以编写以下内容而无需if语句。
DECLARE @cardNo VARCHAR(255)
SELECT TOP (1) @cardNo = cardNo
FROM TABLE1 INNER JOIN
TABLE2
ON TABLE1.objectid = TABLE2.carrierobjectid
ORDER BY cardNo DESC;
UPDATE A
SET A.value = CAST(@cardNo + 1 AS varchar(300))
FROM [db].[dbo].[freefieldassignment] A
WHERE A.[carrierobjectid] = '90465607';