Question

i`m have bundle in my project vendors. Necessary overwrite EditController class. My vendor bundle build with help CedricLambardot AdminGeneratorBundle. I overwrite *-generator.yml and pointed params.bundle_name name my vendor bundle. Owerrite controller too, but him dont work, all the same symfony using controller from vendor.

EditController.php from vendor:

namespace Acme\ProductBundle\Controller\Product;

use Admingenerated\AcmeProductBundle\BaseProductController\EditController as BaseEditController;
// ...

class EditController extends BaseEditController
{
    // ...
}

Overwrited EditController.php

namespace Acme\AnniProductBundle\Controller\Product;

use Acme\ProductBundle\Controller\Product\EditController as BaseEditController;
// ...

class EditController extends BaseEditController
{
    // ...
}

My overwrited *-generator.yml:

generator: admingenerator.generator.doctrine_odm
params:
  model: Acme\AnniProductBundle\Document\Product
  namespace_prefix: Acme
  bundle_name: ProductBundle
  object_actions:
        delete: ~
  fields:
    name:
      label: Name
    # ...
  # ...

My routes:

Acme_ProductBundle_Product_list:
    path:      /product/
    defaults:  { _controller: AcmeAnniProductBundle:Product\List:index }

Acme_ProductBundle_Product_filters:
    path:      /product/filter
    defaults:  { _controller: AcmeAnniProductBundle:Product\List:filter }

Acme_ProductBundle_Product_edit:
    path:      /product/{pk}/edit
    defaults:  { _controller: AcmeAnniProductBundle:Product\Edit:index }

Acme_ProductBundle_Product_update:
    path:      /product/{pk}/update
    defaults:  { _controller: AcmeAnniProductBundle:Product\Edit:update }

Acme_ProductBundle_Product_object:
    path:      /product/{pk}/{action}
    defaults:  { _controller: AcmeAnniProductBundle:Product\Actions:object }

Acme_ProductBundle_Product_new:
    path:      /product/new
    defaults:  { _controller: AcmeAnniProductBundle:Product\New:index }

Acme_ProductBundle_Product_create:
    path:      /product/create
    defaults:  { _controller: AcmeAnniProductBundle:Product\New:create }

What am I doing wrong?

Was it helpful?

Solution 2

Problem with annotation:

Parent controller:

namespace Acme\ProductBundle\Controller\Product;

use Admingenerated\AcmeProductBundle\BaseProductController\EditController as     BaseEditController;
use JMS\DiExtraBundle\Annotation as DI;
// ...

class EditController extends BaseEditController
{
    /** @DI\Inject("doctrine_mongodb.odm.document_manager") */
    private $dm;

    // ...
}

If in overwriten controller write:

/** @DI\Inject("doctrine_mongodb.odm.document_manager") */
private $dm;

All works

OTHER TIPS

Couple of options.

  1. Check where the routes are set. Probably in a routes.yml file somewhere. Adjust the routes to point to your controllers.

  2. If step 1 is not feasible then try bundle inheritance: http://symfony.com/doc/current/cookbook/bundles/inheritance.html

If neither of these approaches work then we will probably need some more details. Might also check the bundle documentation for hints. It's also possible that the controllers might be sending out events which in turn might mean you don't have to override them at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top