Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How can I use a custom action? #257

Closed
JRomeoSalazar opened this issue Aug 9, 2013 · 11 comments
Closed

[Question] How can I use a custom action? #257

JRomeoSalazar opened this issue Aug 9, 2013 · 11 comments

Comments

@JRomeoSalazar
Copy link
Contributor

I have been reading the documentation but "Custom Actions" is not yet written.

Inside SyliusProductBundle there is a file "PrototypeController.php" which extends "ResourceController" and ads the "buildAction" in order to build products based on Prototype.

I'm trying to use this custom action but it is not working:

The error:

Bundle "sylius.controller.prototype" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file?

The route:

sylius_prototype_build:
    pattern: /{id}/build
    methods: [GET, POST]
    defaults:
        _controller:  sylius.controller.prototype:buildAction, id: 1
        _sylius:
            template: SyliusProductBundle:Prototype:build.html.twig
            redirect: sylius_product_show

And this is PrototypeController.php

https://github.com/Sylius/SyliusProductBundle/blob/master/Controller/PrototypeController.php

Thanks.

@arnolanglade
Copy link
Contributor

@JRomeoSalazar : Do you use the bundle standalone? You should register it in your kernel (AppKernel.php) and define your new controller in your configuration.

@JRomeoSalazar
Copy link
Contributor Author

Yes I use the bundle standalone, and I have registered it in AppKernel.php. How can I define the controller in the configuration? I thought it was only necessary to map a new route to the controller as I have done.

This is my AppKernel.php:

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new FOS\RestBundle\FOSRestBundle(),
            new JMS\SerializerBundle\JMSSerializerBundle($this),
            new Sylius\Bundle\ProductBundle\SyliusProductBundle(),
            new Sylius\Bundle\ResourceBundle\SyliusResourceBundle(),
            new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new JMS\AopBundle\JMSAopBundle(),
            new JMS\DiExtraBundle\JMSDiExtraBundle($this),
            new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
            new MDW\DemoBundle\MDWDemoBundle(),
            new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
            new FOS\JsRoutingBundle\FOSJsRoutingBundle(),
            new KTSport\WebBundle\KTSportWebBundle(),
            new JMS\I18nRoutingBundle\JMSI18nRoutingBundle(),
            new JMS\TranslationBundle\JMSTranslationBundle(),
        );

        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            $bundles[] = new Acme\DemoBundle\AcmeDemoBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

        return $bundles;
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
    }
}

@pjedrzejewski
Copy link
Member

@JRomeoSalazar
Copy link
Contributor Author

This is my config.yml:

sylius_product:
    driver: doctrine/orm
    #engine: twig # Templating engine to use by default.
    classes:
        product:
            model: Sylius\Bundle\ProductBundle\Model\Product # The product model class.
            controller: Sylius\Bundle\ResourceBundle\Controller\ResourceController
            #repository: ~
            form: Sylius\Bundle\ProductBundle\Form\Type\ProductType
        property:
            model: Sylius\Bundle\ProductBundle\Model\Property
            controller: Sylius\Bundle\ResourceBundle\Controller\ResourceController
            #repository: ~
            form: Sylius\Bundle\ProductBundle\Form\Type\PropertyType
        prototype:
            model: Sylius\Bundle\ProductBundle\Model\Prototype
            controller: Sylius\Bundle\ProductBundle\Controller\PrototypeController
            #repository: ~
            form: Sylius\Bundle\ProductBundle\Form\Type\PrototypeType

It seems like PrototypeController is already configured but Symfony still throws me the error :(

Any idea?

@pjedrzejewski
Copy link
Member

Your error looks like you would intend to use a bundle named "sylius.controller.prototype" which is of course impossible. Could you paste here the full error trace?

@JRomeoSalazar
Copy link
Contributor Author

Yes, of course, here it is:

Stack trace:

[1] InvalidArgumentException: Bundle "sylius.controller.prototype" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file?
    at n/a
        in C:\wamp\www\symfony\app\bootstrap.php.cache line 2240

    at Symfony\Component\HttpKernel\Kernel->getBundle('sylius.controller.prototype', false)
        in C:\wamp\www\symfony\app\cache\dev\classes.php line 2232

    at Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser->parse('sylius.controller.prototype:buildAction, id: 1')
        in C:\wamp\www\symfony\app\cache\dev\classes.php line 6201

    at JMS\DiExtraBundle\HttpKernel\ControllerResolver->createController('sylius.controller.prototype:buildAction, id: 1')
        in C:\wamp\www\symfony\app\cache\dev\classes.php line 1952

    at Symfony\Component\HttpKernel\Controller\ControllerResolver->getController(object(Request))
        in C:\wamp\www\symfony\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Controller\TraceableControllerResolver.php line 46

    at Symfony\Component\HttpKernel\Controller\TraceableControllerResolver->getController(object(Request))
        in C:\wamp\www\symfony\app\bootstrap.php.cache line 2806

    at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
        in C:\wamp\www\symfony\app\bootstrap.php.cache line 2787

    at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
        in C:\wamp\www\symfony\app\bootstrap.php.cache line 2916

    at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
        in C:\wamp\www\symfony\app\bootstrap.php.cache line 2218

    at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
        in C:\wamp\www\symfony\web\app_dev.php line 28

Logs:

DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest". 
INFO - Matched route "sylius_prototype_build" (parameters: "_controller": "sylius.controller.prototype:buildAction, id: 1", "_sylius": "{"template":"SyliusProductBundle:Prototype:build.html.twig","redirect":"sylius_product_show"}", "_locale": "es", "id": "1", "_route": "sylius_prototype_build") 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\AsseticBundle\EventListener\RequestListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "FOS\RestBundle\EventListener\BodyListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Sylius\Bundle\ResourceBundle\Twig\SyliusResourceExtension::fetchRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger". 
DEBUG - Notified event "kernel.request" to listener "Stof\DoctrineExtensionsBundle\EventListener\LocaleListener::onKernelRequest".
DEBUG - Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException". 
DEBUG - Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ExceptionListener::onKernelException". 
CRITICAL - Uncaught PHP Exception InvalidArgumentException: "Bundle "sylius.controller.prototype" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file?" at C:\wamp\www\symfony\app\bootstrap.php.cache line 2240 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\AsseticBundle\EventListener\RequestListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "FOS\RestBundle\EventListener\BodyListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Sylius\Bundle\ResourceBundle\Twig\SyliusResourceExtension::fetchRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger". 
DEBUG - Notified event "kernel.request" to listener "Stof\DoctrineExtensionsBundle\EventListener\LocaleListener::onKernelRequest".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "FOS\RestBundle\EventListener\FormatListener::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Acme\DemoBundle\EventListener\ControllerListener::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController". 

@pjedrzejewski
Copy link
Member

You have something extra here - _controller: sylius.controller.prototype:buildAction, id: 1.
The id: 1 should go below, if needed at all.

@JRomeoSalazar
Copy link
Contributor Author

That's it! I should pass to the form the prototype id instead to the controller. But now I have another problem, the same as this #249 but with another field, in this case, "value".

Automatic initialization is only supported on root forms. You should set the "auto_initialize" option to false on the field "value".

Do you know why?

@pjedrzejewski
Copy link
Member

Do you use the latest version? Try composer update sylius/product-bundle.

@JRomeoSalazar
Copy link
Contributor Author

Yes, I have just updated the bundle as you have said. I use 0.1.*
Error continues. Also if I try to update a "choice" Property, I get the same error.

@stloyd
Copy link
Contributor

stloyd commented Oct 24, 2013

We don't support version 0.1, please try to use 1.0@dev and ping here if issue still occurs.

@stloyd stloyd closed this as completed Oct 24, 2013
pamil pushed a commit to pamil/Sylius that referenced this issue Mar 21, 2016
Fixed missing sign and parentheses
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants