Php symfony 3-控制器返回单独函数生成错误
只是想知道为什么这不起作用 将JSON返回放在单独的方法中时,我在控制器中遇到以下错误:Php symfony 3-控制器返回单独函数生成错误,php,json,symfony,controller,Php,Json,Symfony,Controller,只是想知道为什么这不起作用 将JSON返回放在单独的方法中时,我在控制器中遇到以下错误: The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller? (500 Internal Server Error) 设置如下所示: 控制器 namespace UsedBundle\Controller; use Sen
The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller? (500 Internal Server Error)
设置如下所示:
控制器
namespace UsedBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
...
use Symfony\Component\HttpFoundation\JsonResponse;
class AccountController extends Controller
{
private $status;
private $message;
private $data;
/**
* @Route("/mon-compte", name="account_page")
*/
public function showAccount(Request $request){
$factory = $this->get('security.encoder_factory');
if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
throw $this->createAccessDeniedException();
}
$user = $this->getUser();
$session = $request->getSession();
$email = $session->get('email');
$em = $this->getDoctrine('doctrine')->getManager('used');
$this->user_info = $em->getRepository('UsedBundle:User')
->UserAccountInfoAction( $email );
$form = $this->createForm(UserType::class, $user);
if ($request->isMethod('POST')) {
if($_POST['action'] == 'update_user'){
$this->updateProfile($request, $user, $form, $em);
}elseif($_POST['action'] == 'delete_user'){
$this->deleteUser( $user, $em );
}elseif($_POST['action'] == 'update_password'){
$this->updatePassword( $user, $em, $factory);
}
// \Doctrine\Common\Util\Debug::dump($this->data);
$this->returnJson();//***** this is generating the error*****
}else{
// populate change profile form
return $this->render('account/account.html.twig', [
'user_info' => $this->user_info,
'form' => $form->createView(),
]);
}
}
然后,在该类的下面,我有returnJson()方法:
如果我将该代码替换showAccount()上的$this->returnJson(),它将正常工作
你知道为什么退货不能作为一种单独的方法吗?还是我遗漏了什么
感谢您的
returnJson
函数将JsonResponse
返回到showcount
函数中,而不是从中返回
这应该起作用:
return $this->returnJson();
谢谢@svgrafov,就这样!
return $this->returnJson();