2013-03-27 157 views
0

所以我意識到在Kohana 3.3中實現PSR-0標準。但是,一定有什麼,因爲我得到一個類未找到錯誤的下面的代碼我不理解:Kohana 3.3 Model :: factory()Class Not Found

$model = Model::factory('MyModel'); 

模型定義位於:

classes/Model/MyModel.php 

它是如何,我班級沒有被準確地找到?

實際代碼:

型號位於classes/Model/VoiceTalent.php

<?php defined('SYSPATH') or die('No direct script access.'); 

    class VoiceTalent 
    { 
     //methods and fields 
    } 

控制器代碼:

$talent = Model::factory('VoiceTalent'); 

確切的錯誤信息:

ErrorException [ Fatal Error ]: Class 'Model_VoiceTalent' not found 
SYSPATH\classes\Kohana\Model.php [ 26 ] 
+1

看起來應該可以工作。一個簡單的調試方法是在自動加載器中添加一些轉儲,並查看它要加載的文件。 – zombor 2013-03-27 15:20:39

+0

我必須同意zombor該文件應該加載,並且,如果您有問題,它可能不是實際加載文件,但與文件本身的內容。 – paquettg 2013-03-27 15:22:39

+0

它正在模型的工廠方法中死去。讓我重新檢查我的所有代碼,如果它確實不是自動加載器問題。 – thatidiotguy 2013-03-27 15:24:02

回答

4

你的類是嚴重的南編輯。

您有:

class VoiceTalent 

應該是:

class Model_VoiceTalent 

,你必須包括它包含在所有文件夾中的類名(由_分隔)。在這種情況下,您只需添加Model_前綴。你可以閱讀更多關於class naming convention in Kohana's docs

+3

這就是我如何得到我的用戶名。 – thatidiotguy 2013-03-27 17:02:35

+2

通過這種邏輯,我們都應該有這個暱稱;)別擔心,我們都在那裏。 – 2013-03-27 18:49:54