| Method | Return Value | Parameters | Description |
|---|---|---|---|
| __construct($options = null) | Void |
| |
| setBootstrap(Zend_Application_Bootstrap_Bootstrapper $bootstrap) | Zend_Application_Resource_Resource |
| |
| getBootstrap() | Zend_Application_Bootstrap_Bootstrapper | N/A | |
| setOptions(array $options) | Zend_Application_Resource_Resource |
| |
| getOptions() | Array | N/A | |
| init() | Mixed | N/A | 采用策略模式: 运行,初始化资源. |
| Method | Return Value | Parameters | Description |
|---|---|---|---|
| __construct($options = null) | Void |
| |
| setBootstrap(Zend_Application_Bootstrap_Bootstrapper $bootstrap) | Zend_Application_Resource_ResourceAbstract |
| |
| getBootstrap() | Zend_Application_Bootstrap_Bootstrapper | N/A | |
| setOptions(array $options) | Zend_Application_Resource_ResourceAbstract |
| |
| getOptions() | Array | N/A | |
$app = new Zend_Application(APPLICATION_ENV, array("pluginPaths" => array("My_Resource" => "My/Resource/",),"resources" => array(// if the following class exists:"My_Resource_View" => array(),// then this is equivalent:"View" => array(),),));以后可以使用短名称引导资源和获取:
$bootstrap->bootstrap("view");$view = $bootstrap->getResource("view");其次,如果没有匹配的插件路径的定义,你可能仍然通过使用资源类的全名。在这种情况下,你可以参考如下使用资源的完整类名:
$app = new Zend_Application(APPLICATION_ENV, array("resources" => array(// This will load the standard "View" resource:"View" => array(),// While this loads a resource with a specific class name:"My_Resource_View" => array(),),));引导资源以及获取方式
$bootstrap->bootstrap("My_Resource_View");$view = $bootstrap->getResource("My_Resource_View");这给我们带来了第三个选项。您可以指定一个明确的名称,将自己注册为一个给定的资源类。这可以通过资源插件类增加 public $_explicitType的字符串值,该值将被用来指定引导插件资源。作为一个例子,让我们来定义我们自己的视图类:
class My_Resource_View extends Zend_Application_Resource_ResourceAbstract{public $_explicitType = "My_View";public function init(){// do some initialization...}}然后,我们可以引导资源或通过它的名字“My_View”获取:$bootstrap->bootstrap("My_View");$view = $bootstrap->getResource("My_View");可以使用这些不同的命名方法,覆盖现有资源,添加您自己的,混合是i用多种资源,以实现复杂的初始化等等。