开发者

Why can't I create a Doctrine model named 'Album'

I'm using Doctrine as ORM in my project but ran against a strange error:

Using following YAML:

Album:
  tableName: dpp_album
  actAs: [Timestampable]
  columns:
    name: string(255)
    description: string(255)
    online: boolean

I then generate my models but upon refreshing my page and autoloading the models, PHP serves this error:

Fatal error: Class 'BaseAlbum' not found in E:\sites\dpp\system\application\models\Album.php on line 13

Strangely enough all my other models are just fine and the Base Classes are found in those cases.

When changing the name 'Album' to something like 'Set' it just works! Ain't that strange?!

So it seems the using 'Album' somehow conflicts, although the error message suggests something else. Change to the plural Albums also doesn't work, anything else is just fine!

Any sugg开发者_开发问答estions?

Thanks!


The problem lies in the autoloading order of the model classes.

Generated 'Base' models live under the 'models/generated' directory and the other ones in the directory above.

Loading order can't be assured, so sometimes a model gets loaded before the Base model upon which it extends and thus throwing this error.

In my bootstrap file, I have now explicitly included the loading order of the directories as following:

Doctrine::loadModels(array(APPPATH.'/models/generated', APPPATH.'/models'));

The documentation uses a lot of examples resulting in generated files but does not mention this behavior when talking about bootstrap configurations.

Anyway, happy this is fixed now! :-)


If the option generateBaseClasses is set (default) generateModelsFromYaml() will in your case create a class AlbumBase (by default in the subdirectory generated) and an empty class Album extends AlbumBase. I.e. if Album is instantiated AlbumBasemust already been known or loaded by some autoloader.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜