在 sonata admin 中扩展 CRUD 控制器以及 PHP 严格标准的问题
extending CRUD controller in sonata admin and problems with PHP Strict standards
我正在使用最新的 (dev-master) sonata admin,我想为 sonata admin 创建我自己的 createAction() 方法。我必须这样做,因为我想在添加到数据库的同时保存一些用户信息。
我的自定义控制器是 - S\CoreBundle\Controller\NewsAdminConroller.php
<?php
namespace S\CoreBundle\Controller;
use Sonata\AdminBundle\Controller\CRUDController as Controller;
use Symfony\Component\Security\Core\SecurityContextInterface;
class NewsAdminController extends Controller
{
/**
* Set the system user ID
*/
private function updateFields($object)
{
//some code - this is my own method
}
public function createAction(Request $request = null)
{
//code for create ... it's almost the same as default code.
}
}
默认 CRUD - Sonata\AdminBundle\Controller\CRUDController.php:
class CRUDController extends Controller
{
public function createAction(Request $request = null)
{
//...
}
}
两个 createAction() 方法具有完全相同的参数,名称 ...
它给我一个错误:
PHP 严格标准:S\CoreBundle\Controller\NewsAdminController::createAction() 的声明应与 Sonata\AdminBundle\Controller\CRUDController::createAction(Symfony\Component\HttpFoundation\Request $request = NULL) 兼容 /home/mark/dev/project/src/S/CoreBundle/Controller/NewsAdminController.php 第 129 行
Sonata\AdminBundle\Controller\CRUDController::createAction(Symfony\Component\HttpFoundation\Request $request = NULL)
需要一个Request Object
,但如果你不声明它,它指向S\CoreBundle\Controller\Request
只需添加
"use Symfony\Component\HttpFoundation\Request;"
在文件顶部。
更新
自提交https://github.com/sonata-project/SonataAdminBundle/commit/49557c302346f57d962b83b31e2931446ff60e9c以来,无需将请求设置为参数。
创建动作只有
Sonata\AdminBundle\Controller\CRUDController::createAction()
我正在使用最新的 (dev-master) sonata admin,我想为 sonata admin 创建我自己的 createAction() 方法。我必须这样做,因为我想在添加到数据库的同时保存一些用户信息。
我的自定义控制器是 - S\CoreBundle\Controller\NewsAdminConroller.php
<?php
namespace S\CoreBundle\Controller;
use Sonata\AdminBundle\Controller\CRUDController as Controller;
use Symfony\Component\Security\Core\SecurityContextInterface;
class NewsAdminController extends Controller
{
/**
* Set the system user ID
*/
private function updateFields($object)
{
//some code - this is my own method
}
public function createAction(Request $request = null)
{
//code for create ... it's almost the same as default code.
}
}
默认 CRUD - Sonata\AdminBundle\Controller\CRUDController.php:
class CRUDController extends Controller
{
public function createAction(Request $request = null)
{
//...
}
}
两个 createAction() 方法具有完全相同的参数,名称 ...
它给我一个错误:
PHP 严格标准:S\CoreBundle\Controller\NewsAdminController::createAction() 的声明应与 Sonata\AdminBundle\Controller\CRUDController::createAction(Symfony\Component\HttpFoundation\Request $request = NULL) 兼容 /home/mark/dev/project/src/S/CoreBundle/Controller/NewsAdminController.php 第 129 行
Sonata\AdminBundle\Controller\CRUDController::createAction(Symfony\Component\HttpFoundation\Request $request = NULL)
需要一个Request Object
,但如果你不声明它,它指向S\CoreBundle\Controller\Request
只需添加
"use Symfony\Component\HttpFoundation\Request;"
在文件顶部。
更新
自提交https://github.com/sonata-project/SonataAdminBundle/commit/49557c302346f57d962b83b31e2931446ff60e9c以来,无需将请求设置为参数。
创建动作只有
Sonata\AdminBundle\Controller\CRUDController::createAction()