我正在尝试从我在项目中执行的所有查询中获取所有错误,并将这些错误重定向到一个名为“error”的控制器,该控制器将按我的意愿处理这些错误。当我重定向所有信息时,问题看起来像是通过get函数生成的url。
我想如果这些信息是通过post发送的,那么这个问题就会消失,但是我显然没有在控制器中使用任何表单。所以,我怎么能对重定向函数说这些信息不应该和url一起,而应该通过post?
可能是我想做的吗?
内部控制器:
try {
$results = $queries->aQuery();
} catch (ErrorException $errorException) {
return $this->redirect($errorException->redirectResponse);
}
在服务查询中:
public function aQuery(){
$query="SELECT * FROM blabla ...";
try {
$stmt = $this->DB->->prepararQuery($query);
$stmt->execute();
$results = $stmt->fetchAll();
} catch (DBALException $DBALException) {
$errorException = new ErrorException($this->router->generate('error',
[
'errorQuery' => $query,
'errorData' => "0 => '".$data1."', 1 ....",
'errorOrigin' => 'a place',
'errorResponseText' => $DBALException->getMessage()
]
));
throw $errorException;
}
}
错误异常:
class ErrorException extends \Exception
{
/**
* @var \Symfony\Component\HttpFoundation\RedirectResponse
*/
public $redirectResponse;
/**
* ErrorException constructor.
* @param \Symfony\Component\HttpFoundation\RedirectResponse $redirectResponse
*/
public function __construct(string $redirectResponse)
{
$this->redirectResponse = $redirectResponse;
}
}