doujianzhi3358 2013-10-27 09:12
浏览 36
已采纳

无法在symfony中加载类型

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%
  • 写回答

2条回答 默认 最新

  • dqce48404 2013-11-01 00:48
    关注

    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").

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动