【发布时间】:2012-08-10 21:05:25
【问题描述】:
我想覆盖 ProfileController 的 FosUserBundle 的编辑操作。我在自己的 UserBundle 中创建了控制器,将编辑操作复制到其中并进行了一些更改。在此控制器中,检查登录用户是否为 instanceOf UserInterFace。显然这不是因为当我转到 /profile/edit 时它会抛出拒绝访问异常
为什么登录的用户不再是 instanceOf UserInterFace?
控制器:
namespace Tennisconnect\UserBundle\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use FOS\UserBundle\Controller\ProfileController as BaseController;
class ProfileController extends BaseController
{
/**
* Edit the user
*/
public function editAction()
{
$user = $this->container->get('security.context')->getToken()->getUser();
if (!is_object($user) || !$user instanceof UserInterface) {
throw new AccessDeniedException('This user does not have access to this section.');
}
$form = $this->container->get('fos_user.profile.form');
$formHandler = $this->container->get('fos_user.profile.form.handler');
$process = $formHandler->process($user);
if ($process) {
$user->upload();
$this->setFlash('fos_user_success', 'profile.flash.updated');
return new RedirectResponse($this->container->get('router')->generate('fos_user_profile_show'));
}
return $this->container->get('templating')->renderResponse(
'FOSUserBundle:Profile:edit.html.'.$this->container->getParameter('fos_user.template.engine'),
array('form' => $form->createView(), 'theme' => $this->container->getParameter('fos_user.template.theme'))
);
}
}
【问题讨论】:
标签: symfony