小编abi*_*iyi的帖子

Symfony2:在SonataAdmin中覆盖createAction()

我一直在谷歌搜索疯狂的最后几天试图找出(没有成功)如何覆盖SonataAdmin操作捕获会话用户名并将其保存在外键字段中.

AttachmentAdminController类:

<?php

namespace Application\Sonata\UserBundle\Controller;

use Sonata\AdminBundle\Controller\CRUDController as Controller;
#use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use FOS\UserBundle\Entity\User;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Bridge\Monolog\Logger;
use Mercury\CargoRecognitionBundle\Entity\Attachment;

class AttachmentAdminController extends Controller
{
    /**
     * (non-PHPdoc)
     * @see Sonata\AdminBundle\Controller.CRUDController::createAction()
     */
    public function createAction()
    {
        $result = parent::createAction();

        if ($this->get('request')->getMethod() == 'POST')
        {
            $flash = $this->get('session')->getFlash('sonata_flash_success');

            if (!empty($flash) && $flash == 'flash_create_success')
            {
                #$userManager = $this->container->get('fos_user.user_manager');
                #$user = $this->container->get('context.user');
                #$userManager = $session->get('username');
                $user = $this->container->get('security.context')->getToken()->getUser()->getUsername();

                $attachment = new Attachment();
                $attachment->setPath('/tmp/image.jpg');
                $attachment->setNotes('nothing interesting to say');
                $attachment->getSystemUser($user);

                $em = $this->getDoctrine()->getEntityManager();
                $em->persist($product);
                $em->flush(); …
Run Code Online (Sandbox Code Playgroud)

php symfony sonata-admin

6
推荐指数
1
解决办法
1万
查看次数

Symfony2和SonataMedia:当前字段未链接到管理员

我一直在努力让SonataMedia与Symfony 2.0.16一起工作......但没有成功.谷歌搜索似乎没有多少人使用该捆绑或有一个我不知道的教程或操作方法,因为我没有得到很多关于我到目前为止的错误消息的信息.

无论如何,我的最后一次尝试给出了下一条错误消息:

The current field `path` is not linked to an admin. Please create one for the target entity : `` 
Run Code Online (Sandbox Code Playgroud)

"path"是用于保存文件图像(相对)路径的字段.

AttachmentAdmin.php

<?php

class AttachmentAdmin extends Admin
{
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add(
                'path',
                'sonata_type_collection',
                array(
                    'required' => true
                ),
                array(
                    'edit' => 'inline',
                    'inline' => 'table',
                    'sortable' => 'position',
                    'targetEntity' => 'Application\Sonata\MediaBundle\Entity\GalleryHasMedia',
                    'link_parameters' => array(
                        'context' => 'attachment'
                    )
                )
            )
            ->add('notes', 'textarea', array('required' => false))
        ;
    }

    // other methods
}
Run Code Online (Sandbox Code Playgroud)

Attachment.php

<?php

class …
Run Code Online (Sandbox Code Playgroud)

php symfony symfony-sonata

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

php ×2

symfony ×2

sonata-admin ×1

symfony-sonata ×1