【发布时间】:2019-09-10 06:37:24
【问题描述】:
我使PlaceInfoAdminController 扩展自Sonata\AdminBundle\Controller\CRUDController
use Sonata\AdminBundle\Controller\CRUDController;
class PlaceInfoAdminController extends CRUDController
{
/**
* Edit action.
*
* @param int|string|null $id
*
* @throws NotFoundHttpException If the object does not exist
* @throws \RuntimeException If no editable field is defined
* @throws AccessDeniedException If access is not granted
*
* @return Response|RedirectResponse
*/
public function editAction($id = null)
{
$request = $this->getRequest();
// the key used to lookup the template
$templateKey = 'edit';
$id = $request->get($this->admin->getIdParameter());
$existingObject = $this->admin->getObject($id);
if (!$existingObject) {
throw $this->createNotFoundException(sprintf('unable to find the object with id: %s', $id));
}
$this->checkParentChildAssociation($request, $existingObject); // calling parent's method
当我调用父类方法时,出现错误。
LogicException:
Call to undefined method Sonata\AdminBundle\Controller\CRUDController::checkParentChildAssociation
at vendor/sonata-project/admin-bundle/src/Controller/CRUDController.php:89
at Sonata\AdminBundle\Controller\CRUDController->__call('checkParentChildAssociation', array(object(Request), object(PlaceInfo)))
(src/Controller/PlaceInfoAdminController.php:35)
at App\Controller\PlaceInfoAdminController->editAction('19')
(vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:151)
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
(vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:68)
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
(vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:200)
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
(web/app_dev.php:28)
从子类调用父类的checkParentChildAssociation()会出现这个错误,但是父类中有函数checkParentChildAssociation()。
怎么了??
【问题讨论】:
-
在
CRUDController.php:89抛出异常 -
checkParentChildAssociation()是私有方法 -
Ohhps ,抱歉这个愚蠢的问题是私人的..
-
但是我怎样才能覆盖editAction....