我希望在Sonata Admin中覆盖控制器,但它会返回:
在null
上调用成员函数get()
services.yml中的代码:
app.admin.model:
class: AppBundle\Admin\ModelAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: Model,label: Model }
arguments:
- null
- AppBundle\Entity\Model
- AppBundle\Controller\ModelController
public: true
控制器中的代码:
namespace AppBundle\Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Sonata\AdminBundle\Controller\CRUDController as Controller;
use Symfony\Component\HttpFoundation\Response;
class ModelController extends Controller {
/**
*
* @param int|string|null $id
*
* @throws NotFoundHttpException
*
* @return Response
*/
public function showAction($id = null) {
$request = $this->getRequest();
$id = $request->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object) {
throw $this->createNotFoundException(sprintf('unable to find the object with id : %s', $id));
}
$this->admin->checkAccess('show', $object);
$preResponse = $this->preShow($request, $object);
if (null !== $preResponse) {
return $preResponse;
}
$this->admin->setSubject($object);
return $this->render($this->admin->getTemplate('show'), array(
'action' => 'show',
'object' => $object,
'elements' => $this->admin->getShow(),
), null);
}
}
目前这是供应商的简单复制/粘贴,当我在ma视图中返回时,我收到此错误:
CRITICAL
16:31:37
php Call to a member function get() on null
CRITICAL
16:31:37
request Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError: "Call to a member function get() on null" at /var/www/html/acianovintra2/vendor/sonata-project/admin-bundle/src/Controller/CRUDController.php line 988
你能帮我吗?