2013-10-27 50 views
1

加載類型我使用FOSOAuthServerBundleSymfony,我收到錯誤以下錯誤:無法symfony的

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% 
+0

[Symfony2:無法加載類型「MyType」]的可能的副本 - (http://stackoverflow.com/questions/7218689/symfony2-could-not-load-type-mytype) - 當你剛接觸這個,期望的是你在問這個問題之前先研究這個問題。在處理常見的錯誤消息時,這是特別必要的,因爲這些消息很容易搜索。在您列出了迄今爲止已嘗試的內容並解釋了爲什麼所有這些嘗試都不起作用(參考現場的現有Q&A材料)之後,您可以創建一個問題。請通過編輯來詳細說明您現有的問題。 – hakre

+0

@hakre對不起,但我不知道這個重複的問題將如何解決我的問題 – Hunt

+0

那麼,那麼解釋一下,如果你打算嘗試它。否則,請先與其他相關資料聯繫。通常情況下,一條錯誤消息正在向您傳達某些信息,這是理解其內容的第一部分。在這種情況下,類型'travel_oauth_server_auth'保持未定義。它在代碼中定義在哪裏?這樣的ID也沒有服務。 – hakre

回答

0

詳情老實說,我認爲你需要做的就是添加

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

對XML和擺脫你的YAML文件中的服務定義的,我也看到2名稱空間根類型的旅行與旅行。你可能仍然有標記的服務,請參閱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> 

在這裏找到的第二個參數沒有找到,它真的很難告訴你:-)(與其他任何「框架」相比)。

+0

當我嘗試你的確切的代碼,我得到的錯誤(通常它是我自己的類型,但你明白我用上面提到的一個):無法加載類型Travel \ HomeBundle \ Form \ Type \ AuthorizeFormType。你認爲它有什麼關係你寫了什麼或者我應該問另一個問題? – etiennenoel

+0

好吧,它只是yml中參數的順序! – etiennenoel

0

通過如下參數:

<argument>%travel_oauth_server_auth%</argument> 

你可以找到Symfony2 Official Documentation

+0

以上它說'ParameterNotFoundException:服務「travel_oauth_server.authorize.form」具有依賴於一個不存在的參數「travel_oauth_server_auth」:( – Hunt

+0

你有什麼解決這個問題 – Hunt