使用基于 Zend 的命名约定或完全没有约定的 Symfony 2 自动加载类 [英] Autoload classes with Zend based naming convention or no convention at all with Symfony 2

查看:31
本文介绍了使用基于 Zend 的命名约定或完全没有约定的 Symfony 2 自动加载类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 Symfony2 ClassLoader 自动加载不遵循 PEAR 命名约定且不使用命名空间的类?

How can I use the Symfony2 ClassLoader to autoload classes that dont follow PEAR naming conventions and don't use namespaces?

从 symfony2 文档看来,这是不可能的.如何包含 API 帮助程序库或其他不遵循这些类型约定的文件(即它们遵循 Zend 约定或根本没有命名约定)?

It seems from the symfony2 docs that this isn't possible. How does one include API helper libraries or other files that don't follow these types of conventions (i.e. they instead follow Zend conventions or no naming conventions at all)?

推荐答案

你应该使用 spl_autoload_register().这会让你有几个自动加载器一个接一个地运行,直到一个成功加载所需的类.

You should register autoloading functions for those classes using spl_autoload_register(). This will let you have several autoloaders rune one after another, until one manages to load requied class.

这篇关于使用基于 Zend 的命名约定或完全没有约定的 Symfony 2 自动加载类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆