Zend_Framework - 类命名
我想在我的 Zend Framework 项目中使用这样的代码:
public function indexAction() {
$user = new User();
$user->name = "Guest";
$user->save();
}
对我来说最重要的是该类仅被称为 User
而不是 App_Model_User
但我怎么能管理那个? 我想我可以将模型文件夹中的文件 User.php
的路径添加到 include_path:
<?php
class User {
/* Some code */
}
但是如何配置自动加载器来加载该文件/类? 目前,我正在使用带有应用程序命名空间(“App”)的自动加载器来加载名为 App_Model_User
的类,该类可以工作,但我认为类命名不正确。它应该更干净、更清晰。
I wanted to use code like this in my Zend Framework project:
public function indexAction() {
$user = new User();
$user->name = "Guest";
$user->save();
}
The main thing that is important for me is that the class is called just User
and not App_Model_User
but how could I manage that?
I thought I could add the path to the file User.php
in the model-folder to the include_path:
<?php
class User {
/* Some code */
}
But how could I config the autoloader to load that file/class?
Currently I'm using the autoloader with the appnamespace ("App") to load classes called App_Model_User
which works but the class naming is not the right I think. It should be cleaner and clearer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用
set_include_path
如下:然后自动加载器拾取我放入 /application/models 中的任何模型(具有任何名称)。以上是我唯一面向公众的脚本(index.php)。这就是我设置自动加载器的方式:
第二行将确保不必显式包含您的模型。请参阅:
http://framework.zend.com/manual/en/zend .loader.autoloader.html
I use
set_include_path
as follows:Then the autoloader picks up any models (with any name) which I put in /application/models. The above is in my only public facing script (index.php). This is how I set up the autoloader:
The second line will ensure that your models do not have to be explicitly included. See:
http://framework.zend.com/manual/en/zend.loader.autoloader.html
你的 PHP 版本是什么?您可以使用命名空间。
What is your version of PHP? You can use namespaces.