2

以下のように、バンドルに services.yml があります。

parameters:
     application_stock.admin.stocklevels: Application\StockBundle\Admin\StockLevelView
#    application_stock.example.class: Application\StockBundle\Example

services:
#    application_stock.example:
#        class: %application_stock.example.class%
#        arguments: [@service_id, "plain_value", %parameter%]
     application_stock:
         class: "%application_stock.admin.stocklevels%"
         tags:
             - { name: sonata.admin, manager_type: orm, group: application_stock, label: stock }
         arguments: [ '', Application\StockBundle\Entity\StockLevels, ApplicationStockBundle:StockLevels ]

しかし、サービスを変更しようとしているとき

- @security.context
- { null, Application\StockBundle\Entity\StockLevels, ApplicationStockBundle:StockLevels }

その後、エラーが表示されます

ContextErrorException: Notice: Undefined offset: 2 in C:\wamp\www\test\vendor
\sonata-project\admin-bundle\Sonata\AdminBundle\DependencyInjection\Compiler\
AddDependencyCallsCompilerPass.php line 48

誰でもその問題を解決するのを手伝ってくれませんか?

編集:

追加後

calls:
    - [setContainer, [@service_container]]
    - [setSecurityContext, [@security.context]]

エラーが発生しています:

Call to a member function getUser() on a non-object in

StockLevelView.php:

<?php
namespace Application\StockBundle\Admin;

use Application\StockBundle\Entity\StockLevels;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;

use Knp\Menu\ItemInterface as MenuItemInterface;

class StockLevelView extends Admin implements ContainerAwareInterface
{

/**
 * @var ContainerInterface
 */
private $container;

private $adminId;

/**
 * {@inheritDoc}
 */
public function setContainer(ContainerInterface $container = null)
{
    $this->container = $container;
}

public function setSecurityContext($securityContext)
{
    $this->adminId = $securityContext->getToken()->getUser();
}

...rest of code
4

2 に答える 2

2

次のように使用してください。

application_stock:
    class: "%application_stock.admin.stocklevels%"
    tags:
        - { name: sonata.admin, manager_type: orm, group: application_stock, label: stock }
    arguments: [ '', Application\StockBundle\Entity\StockLevels, ApplicationStockBundle:StockLevels ]
    calls:
        - [setSecurityContext, [@security.context]]

そして、public function setSecurityContext($securityContext) { ... }セッターを作成して、管理クラスでセキュリティ コンテキストをキャプチャします。

于 2013-07-26T06:54:57.047 に答える