I got the following error when I add a custom action in Sonata Admin
FatalErrorException: Error: Class 'Symfony\Component\Debug\Exception\FlattenException' not found in /myproject_path/AppBundle/Admin/BalticsAdmin.php line 106
What is this problem please share me
HERE IS THE CODE
In admin class
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
................................
.................
->add('_action', 'actions', array(
'actions' => array(
'show' => array(),
'edit' => array(),
'delete' => array(),
'upload' => array('template' => 'SteelGuruBundle:CRUD:list__action_upload.html.twig'),
)
));
}
protected function configureRoutes(RouteCollection $collection)
{
$collection->add('upload', $this->getRouterIdParameter().'/upload');
}
THEN I cREATE a controller class in src/.../.../Controller/CRUDController.php with following codes
namespace ...\AppBundle\Controller;
use Sonata\AdminBundle\Controller\CRUDController as Controller;
class CRUDController extends Controller
{
public function uploadAction()
{
$id = $this->get('request')->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object) {
throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
}
}
}
Then I create a template in src/.../AppBundle/Resources/views/CRUD/list__action_upload.html.twig with the following code
<a class="btn btn-small" href="{{ admin.generateObjectUrl('upload', object) }}">Upload</a>
and then in services.yml I added the following
sg_app.admin.baltic:
class: ...\AppBundle\Admin\BalticsAdmin
tags:
- { name: sonata.admin, manager_type: orm, audit:false, group: Test, label: Upload}
arguments: [null, ...\AppBundle\Entity\Baltics, ...AppBundle:CRUD]
Thanks for your response
EntityAdmin.php
would be a good start... – Geert Wille