1

I am using FOSOAuthServerBundle and Symfony and I am getting error following error:

Could not load type "travel_oauth_server_auth"
500 Internal Server Error - Exception

Here is my service.xml file, as I am new to Symfony so I don't know why I am get this error.

<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

    <services>

        <service id="travel_oauth_server.authorize.form_type" class="travel\HomeBundle\Form\Type\AuthorizeFormType">
        </service>

        <service id="travel_oauth_server.authorize.form" factory-method="createNamed" factory-service="form.factory" class="Symfony\Component\Form\Form">
            <argument type="service" id="travel_oauth_server.authorize.form_type" />
            <argument>%travel_oauth_server_auth%</argument>
        </service>

        <service id="travel_oauth_server.authorize.form_handler" class="travel\HomeBundle\Form\Handler\AuthorizeFormHandler" scope="request">
            <argument type="service" id="travel_oauth_server.authorize.form" />
            <argument type="service" id="request" />
            <argument type="service" id="security.context" />
            <argument type="service" id="fos_oauth_server.server" />
        </service>

     </services>

</container>

Here is the form that I have created AuthorizeFormType:

<?php
namespace Travel\HomeBundle\Form\Type;

use Symfony\Component\Form\FormBuilderInterface;  
use Symfony\Component\Form\AbstractType;

class AuthorizeFormType extends AbstractType  
{  
    public function buildForm(FormBuilderInterface $builder, array $options)  
    {  
        $builder->add('allowAccess', 'checkbox', array(  
            'label' => 'Allow access',  
        ));  
    }  

    public function getDefaultOptions(array $options)  
    {  
        return array('data_class' => 'Travel\HomeBundle\Form\Model\Authorize');  
    }  

    public function getName()  
    {  
        return 'travel_oauth_server_authorize';  
    } 
}

Update in config file according the reference question which is possibly duplication but i am still getting the same error

parameters:
    travel_oauth_server_auth.class: Travel\HomeBundle\Form\Type\AuthorizeFormType
services:
    travel_oauth_server_auth:
           class: %travel_oauth_server_auth%
Hunt
  • 8,215
  • 28
  • 116
  • 256
  • possible duplicate of [Symfony2: Could not load type "MyType"](http://stackoverflow.com/questions/7218689/symfony2-could-not-load-type-mytype) - As you're new to this, the expectation is that you research on the issue first before asking the question. That is especially required when dealing with common error messages as those are easy to search for. After you've outlined what you've tried so far and explained why all those tries didn't work (referencing the existing Q&A material on site), you can create a question. Please elaborate on your existing question now by editing it. – hakre Oct 27 '13 at 09:14
  • @hakre sorry but i dont know how this duplicate question will solve my issue – Hunt Oct 27 '13 at 09:19
  • Well, then explain that exactly if you are intending to try it. Otherwise please relate to other related materials first. Normally an error message is communicating something to you, and that's the first part to understand what it says. In this case the type `travel_oauth_server_auth` remains undefined. Where is it defined in your code? There also is no service with such id. – hakre Oct 27 '13 at 09:22
  • how do i define it and where do i define it ? – Hunt Oct 27 '13 at 09:26
  • A type (also named class) is defined in PHP with the `class` keyword, the exact how is outlined in the PHP manual: http://php.net/language.oop5 - Are you familiar with these basics? I ask because you did ask where to define a type. For the services, you define the services in `services.xml` (in your case) or in `config.yml` (as in the linked reference question). That depends on the type of configuration you've decided on, so you *should* actually know. The exact how is outlined in the Symfony manual: http://symfony.com/doc/current/book/service_container.html - more clear? – hakre Oct 27 '13 at 09:29
  • can you review my update above – Hunt Oct 27 '13 at 09:55

2 Answers2

0

Pass the parameter like this:

<argument>%travel_oauth_server_auth%</argument>

You can find more details on Symfony2 Official Documentation

Udan
  • 5,429
  • 2
  • 28
  • 34
  • its saying `ParameterNotFoundException: The service "travel_oauth_server.authorize.form" has a dependency on a non-existent parameter "travel_oauth_server_auth"` :( – Hunt Oct 27 '13 at 11:27
0

I honestly think all you need to do is add

<service id="travel_oauth_server_auth" class="%travel_oauth_server_auth.class%" scope="request">
       ...
</service>

To your XML and get rid of the service definition in your YAML file, also I see 2 types of namespace roots travel vs Travel. You might still have to tag the service, see http://symfony.com/doc/current/book/forms.html#defining-your-forms-as-services

parameters:
  travel_oauth_server_auth.class: Travel\HomeBundle\Form\Type\AuthorizeFormType
services:
  travel_oauth_server_auth:
    class: %travel_oauth_server_auth%

Was not correct to begin with, as you'd want

parameters:
  travel_oauth_server_auth.class: "Travel\HomeBundle\Form\Type\AuthorizeFormType"
services:
  travel_oauth_server_auth:
    class: %travel_oauth_server_auth.class%

The error you are receiving

ParameterNotFoundException: The service "travel_oauth_server.authorize.form" has a dependency on a non-existent parameter "travel_oauth_server_auth" :( 

is because of

<service id="travel_oauth_server.authorize.form" factory-method="createNamed" factory-service="form.factory" class="Symfony\Component\Form\Form">
        <argument type="service" id="travel_oauth_server.authorize.form_type" />
        <argument>%travel_oauth_server_auth%</argument>
 </service>

The second passed argument in here is not found, and it really tries hard to tell you so :-) ( compared to any other "framework").

wtfzdotnet
  • 1,022
  • 8
  • 11
  • When I try your exact code, I get the error (normally it is my own type, but so you understand I used the one mentioned above): Could not load type Travel\HomeBundle\Form\Type\AuthorizeFormType. Do you think it has something to do with what you wrote or I should ask another question ? – etiennenoel Oct 15 '14 at 02:46
  • Alright, it was simply the order of the arguments in yml ! – etiennenoel Oct 15 '14 at 02:53