我在Sonata Admin
中添加自定义操作时出现以下错误FatalErrorException:错误:在/myproject_path/AppBundle/Admin/BalticsAdmin.php第106行中找不到类'Symfony \ Component \ Debug \ Exception \ FlattenException'
这是什么问题请与我分享
这是代码
在管理类
中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');
}
然后我在src /.../.../ Controller / CRUDController.php中使用以下代码创建一个控制器类
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));
}
}
}
然后我在src /.../ AppBundle / Resources / views / CRUD / list__action_upload.html.twig中使用以下代码创建模板
<a class="btn btn-small" href="{{ admin.generateObjectUrl('upload', object) }}">Upload</a>
然后在services.yml中添加了以下内容
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]
感谢您的回复
答案 0 :(得分:0)
我有类似的问题,发现我必须添加
use Sonata\AdminBundle\Route\RouteCollection;
指向管理员(在您的案例中为BalticAdmin)。