简体   繁体   中英

extending CRUD controller in sonata admin and problems with PHP Strict standards

I'm using latest (dev-master) sonata admin and I want to create my own createAction() method for sonata admin. I have to do that, because I want to save some user information, while adding to database.

My custom controller is - 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. 
    }
}

Default CRUD - Sonata\\AdminBundle\\Controller\\CRUDController.php:

class CRUDController extends Controller
{
    public function createAction(Request $request = null)
    {
         //...
    }
}

Both createAction() methods have exactly the same arguments, name ...

And it throw's me an error:

PHP Strict Standards: Declaration of S\\CoreBundle\\Controller\\NewsAdminController::createAction() should be compatible with Sonata\\AdminBundle\\Controller\\CRUDController::createAction(Symfony\\Component\\HttpFoundation\\Request $request = NULL) in /home/mark/dev/project/src/S/CoreBundle/Controller/NewsAdminController.php on line 129

The Sonata\\AdminBundle\\Controller\\CRUDController::createAction(Symfony\\Component\\HttpFoundation\\Request $request = NULL)

Needs a Request Object , but if you don't declare it, it point to S\\CoreBundle\\Controller\\Request

Just add "use Symfony\\Component\\HttpFoundation\\Request;" in top of file.

Update

Since the commit https://github.com/sonata-project/SonataAdminBundle/commit/49557c302346f57d962b83b31e2931446ff60e9c , there is no need to set the request as parameter.

The create Action is only

Sonata\\AdminBundle\\Controller\\CRUDController::createAction()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM