繁体   English   中英

无法在symfony中加载类型

[英]Could not load type in symfony

我正在使用FOSOAuthServerBundleSymfony并且由于以下错误而出现错误:

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

这是我的service.xml文件,因为我是Symfony的新手,所以我不知道为什么会收到此错误。

<?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>

这是我创建的表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';  
    } 
}

根据参考问题在配置文件中更新,这可能是重复的,但我仍然遇到相同的错误

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

像这样传递参数:

<argument>%travel_oauth_server_auth%</argument>

您可以在Symfony2官方文档中找到更多详细信息。

老实说,我需要做的就是添加

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

对于您的XML并摆脱YAML文件中的服务定义,我还看到了两种类型的名称空间根:旅行vs旅行。 您可能仍需要标记服务,请参阅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%

一开始是不正确的

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

您收到的错误

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

是因为

<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>

在这里找不到第二个传递的参数,它真的很难告诉您:-)(与任何其他“框架”相比)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM