开发者

naming models in zend

If i m not following the naming structure for the model name ( eg Application_Model_DbTable_Users in Users.开发者_高级运维php in model folder), i m getting error on controller. instead of writing it as Application_Model_DbTable_Users , i want to write it simply as Users in Users.php in model folder. i know this is achievable in zend but how ?? i dont know. Please help in this concern. i guess something must be done in bootstrap.php or index.php for configuring autoloader.... whatever is the exact solution..... but please help me out for this. thanks in advance


How do you know this is possible? The Zend Framework has a strict naming syntax to be able to load all files automatically. The autoloader uses the prefixes (like Application_Model_) to determine where the file is located. Without the prefix, this is not possible.

Sometimes during explanation of ZF's behaviour, it's too much work to type all the time Application_Model_User and instead of it, to make it more clear, things like User are used. This does not mean you can use this name in your application.

A last possibility is namespaces, but in the stable ZF it isn't used yet.


ZF follows PEAR naming convention in that the folder hierarchy corresponds to the naming of the classes, e.g. Foo_Bar_Baz will be in the folder Foo/Bar/Baz.php. The autoloader will try to find this path relative to the configured include path.

This means, you can either put all your classes into a single top level directory already known by the Autoloader or put an additional include path or - and that's the better option - add an additional autoloader to the default autoloader that knows how to map class names to files.

Please refer to the ZF Reference Guide on Autoloading for details.


you could implement an custom autoloader which simply prepends the classname with the model path. in the documentation of the Zend_Loader there is an example on how to build your own autoloader plugin. basically just an search & replace task.

However, i strongly recommend not using this approach, as your global namespace would be polluted a lot. at least use a simple prefix (like Model_).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜