repincln repincln - 7 months ago 28
PHP Question

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

Answer

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.

Comments