我从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()
。
怎么了?
答案 0 :(得分:1)
如果不覆盖该方法,则需要使用父级关键字来调用它。
parent::checkParentChildAssociation($request, $existingObject);