使用 Symfony 1.4 的自动加载器加载命名空间类?
如何在 Symfony 1.4 中为自动加载器类功能注册命名空间(使用 PHP 5.3)(如
How to register namespaces (with PHP 5.3) in the Symfony 1.4 for the autoloader class feature (like the Symfony 2.0)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在 Symfony 1.4 框架中使用 Symfony2 的 Autoloader。
1.将 Symfony2 类加载器复制到 Symfony 1.4 沙箱项目的供应商目录:
2.按如下方式修改 SF_ROOT_DIR/config/ProjectConfiguration.class.php 文件:
3. 注册所需的命名空间:
例如。我想加载类:
文件名必须是:
并注册命名空间如下:
You can use Autoloader from Symfony2 in Symfony 1.4 framework.
1. Copy Symfony2 classloaders to vendor directory of your Symfony 1.4 sandbox project:
2. Modify your SF_ROOT_DIR/config/ProjectConfiguration.class.php file as follows:
3. Register desired namespaces:
eg. I want to load class:
Filename must be:
and registered namespace as follows:
您可以使用 Composer,这非常简单。只需将其安装在您的计算机上(从 2015 年起您可能已经安装了)并在您的项目文件夹中运行:
然后您可以使用 Composer 安装您想要的所有软件包,并将这一行包含在您的
ProjectConfiguration.class.php< /code>:
请注意,如果您更改了默认的 Symfony1.4 目录结构,路径可能会有所不同。
You can use Composer and it's very easy. Just install it on your machine (you probably have already since it's 2015 now) and run in your project folder:
You can then install all the packages you want with composer and include just this line in your
ProjectConfiguration.class.php
:Note that paths may differ if you changed the default Symfony1.4 directory structure.
Symfony 使用 spl_autoload_register() 函数来注册自己的自动加载器 (sfAutoload)。
您可以在项目/应用程序/插件的
initialize()
函数中注册自己的处理程序。 (以适用者为准)。例如,这也是 Swift_Mailer 插件的作用:它在需要时注册自己的自动加载器。
Symfony uses the
spl_autoload_register()
function to register its own autoloader (sfAutoload
).You can register your own handler in the
initialize()
function of your Project/Application/Plugin. (whichever applies).This is, for example, also what the
Swift_Mailer
plugin does: it registers its own autoloader when needed.