Home Backend Development PHP Tutorial Zend Framework教程之资源(Resources)用法实例详解_php实例

Zend Framework教程之资源(Resources)用法实例详解_php实例

Jun 07, 2016 pm 05:08 PM
framework resources zend resource

本文实例讲述了Zend Framework教程之资源(Resources)用法。分享给大家供大家参考,具体如下:

Zend_Application_Resource_Resource

Zend_Application_Bootstrap_ResourceBootstrapper是引导类加载注册资源插件使用的接口。
Zend_Application_Resource_Resource是一个资源插件接口。
Zend_Application_Resource_Resource通常被用于实现了Zend_Application_Bootstrap_ResourceBootstrapper的引导类中。

资源插件是一个可配置,预加载的和可以通过策略模式初始化资源的接口。

Zend_Application_Resource_Resource Interface

Method Return Value Parameters Description
__construct($options = null) Void
  • $options:可选. 配置资源.

 

setBootstrap(Zend_Application_Bootstrap_Bootstrapper $bootstrap) Zend_Application_Resource_Resource
  • $bootstrap:必填. 初始化资源的父引导类

 

getBootstrap() Zend_Application_Bootstrap_Bootstrapper N/A


setOptions(array $options) Zend_Application_Resource_Resource
  • $options:必填. 配置选项.

 

getOptions() Array N/A

 

init() Mixed N/A

采用策略模式: 运行,初始化资源.


Zend_Application_Resource_ResourceAbstract

Zend_Application_Resource_ResourceAbstract是一个抽象类,实现了Zend_Application_Resource_Resource接口,为创建自定义插件资源提供了一个便捷的方式。

注:这个抽象类没有实现init()方法,可以继承使用这个抽象类,自定义实现init方法。

Zend_Application_Resource_ResourceAbstract Methods

Method Return Value Parameters Description
__construct($options = null) Void
  • $options:可选. 配置资源

 

setBootstrap(Zend_Application_Bootstrap_Bootstrapper $bootstrap) Zend_Application_Resource_ResourceAbstract
  • $bootstrap:必填.  

 

getBootstrap() Zend_Application_Bootstrap_Bootstrapper N/A

 

setOptions(array $options) Zend_Application_Resource_ResourceAbstract
  • $options:必填.  

 

getOptions() Array N/A

 


资源名称

注册插件资源时,出现的一个问题是你应该如何从父引导类。有三种不同的机制,可以使用,这取决于你是如何配置的引导和它的插件资源。

首先,如果你的插件名称定义包含前缀路径,您可以通过他们的“短名称” - 即类的名称的一部分。例如,类“Zend_Application_Resource_View”的短名称是“View”,如果前缀路径“Zend_Application_Resource”已注册。您可能使用类的全名或短名称注册他们:

$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(),
  ),
));

Copy after login

以后可以使用短名称引导资源和获取:

$bootstrap->bootstrap('view');
$view = $bootstrap->getResource('view');

Copy after login

其次,如果没有匹配的插件路径的定义,你可能仍然通过使用资源类的全名。在这种情况下,你可以参考如下使用资源的完整类名:

$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(),
  ),
));

Copy after login

引导资源以及获取方式

$bootstrap->bootstrap('My_Resource_View');
$view = $bootstrap->getResource('My_Resource_View');
Copy after login

这给我们带来了第三个选项。您可以指定一个明确的名称,将自己注册为一个给定的资源类。这可以通过资源插件类增加 public $_explicitType的字符串值,该值将被用来指定引导插件资源。作为一个例子,让我们来定义我们自己的视图类:

class My_Resource_View extends Zend_Application_Resource_ResourceAbstract
{
  public $_explicitType = 'My_View';
  public function init()
  {
    // do some initialization...
  }
}

Copy after login

然后,我们可以引导资源或通过它的名字“My_View”获取:

$bootstrap->bootstrap('My_View');
$view = $bootstrap->getResource('My_View');

Copy after login

可以使用这些不同的命名方法,覆盖现有资源,添加您自己的,混合是i用多种资源,以实现复杂的初始化等等。

更多关于zend相关内容感兴趣的读者可查看本站专题:《Zend FrameWork框架入门教程》、《php优秀开发框架总结》、《Yii框架入门及常用技巧总结》、《ThinkPHP入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Microsoft NET Framework Installation Issues Error Code 0x800c0006 Fix Microsoft NET Framework Installation Issues Error Code 0x800c0006 Fix May 05, 2023 pm 04:01 PM

.NET Framework 4 is required by developers and end users to run the latest versions of applications on Windows. However, while downloading and installing .NET Framework 4, many users complained that the installer stopped midway, displaying the following error message - " .NET Framework 4 has not been installed because Download failed with error code 0x800c0006 ". If you are also experiencing it while installing .NETFramework4 on your device then you are at the right place

How to identify Windows upgrade issues using SetupDiag on Windows 11/10 How to identify Windows upgrade issues using SetupDiag on Windows 11/10 Apr 17, 2023 am 10:07 AM

Whenever your Windows 11 or Windows 10 PC has an upgrade or update issue, you will usually see an error code indicating the actual reason behind the failure. However, sometimes confusion can arise when an upgrade or update fails without an error code being displayed. With handy error codes, you know exactly where the problem is so you can try to fix it. But since no error code appears, it becomes challenging to identify the issue and resolve it. This will take up a lot of your time to simply find out the reason behind the error. In this case, you can try using a dedicated tool called SetupDiag provided by Microsoft that helps you easily identify the real reason behind the error.

SCNotification has stopped working [5 steps to fix it] SCNotification has stopped working [5 steps to fix it] May 17, 2023 pm 09:35 PM

As a Windows user, you are likely to encounter SCNotification has stopped working error every time you start your computer. SCNotification.exe is a Microsoft system notification file that crashes every time you start your PC due to permission errors and network failures. This error is also known by its problematic event name. So you might not see this as SCNotification having stopped working, but as bug clr20r3. In this article, we will explore all the steps you need to take to fix SCNotification has stopped working so that it doesn’t bother you again. What is SCNotification.e

How to find resources on 115 network disk How to find resources on 115 network disk Feb 23, 2024 pm 05:10 PM

There will be a lot of resources in the 115 network disk, so how to find resources? Users can search for the resources they need in the software, then enter the download interface, and then choose to save to the network disk. This introduction to the method of finding resources on 115 network disk can tell you the specific content. The following is a detailed introduction, come and take a look. How to find resources on 115 network disk? Answer: Search the content in the software, and then click to save to the network disk. Detailed introduction: 1. First enter the resources you want in the app. 2. Then click the keyword link that appears. 3. Then enter the download interface. 4. Click Save to network disk inside.

Microsoft .NET Framework 4.5.2, 4.6, and 4.6.1 will end support in April 2022 Microsoft .NET Framework 4.5.2, 4.6, and 4.6.1 will end support in April 2022 Apr 17, 2023 pm 02:25 PM

Microsoft Windows users who have installed Microsoft.NET version 4.5.2, 4.6, or 4.6.1 must install a newer version of the Microsoft Framework if they want Microsoft to support the framework through future product updates. According to Microsoft, all three frameworks will cease support on April 26, 2022. After the support date ends, the product will not receive "security fixes or technical support." Most home devices are kept up to date through Windows updates. These devices already have newer versions of frameworks installed, such as .NET Framework 4.8. Devices that are not updating automatically may

How to implement jar operation in springboot and copy resources files to the specified directory How to implement jar operation in springboot and copy resources files to the specified directory May 12, 2023 pm 09:34 PM

Springboot implements jar operation and copies resources files to the specified directory 1. Requirements During the project development process, all resources in the project resources/static/ directory need to be copied to the specified directory. Video files need to be downloaded in the company's project. Since the download has an html page, the corresponding static resource files are used to load the multi-channel video, such as js, css.jwplayer, jquery.js and other files, jars made by maven and The path of the usually published project is blocked, so when reading the path, the path of the jar is obtained, and the file path in the jar cannot be obtained. 2. Idea According to my needs, the idea of ​​copying is probably to obtain it first

Why did Han Xiaoquan suddenly have no resources? Why did Han Xiaoquan suddenly have no resources? Feb 24, 2024 pm 03:22 PM

Han Xiaoquan is a software that can watch many Korean dramas, so why is there suddenly no resource? This software may have no resources due to network problems, version problems, or copyright issues. This article about the reason why Han Xiaoquan suddenly has no resources can tell you the specific content. The following is a detailed introduction, come and take a look. Why did Han Xiaoquan suddenly have no resources? Answer: Due to network problems, version problems, and copyright issues, detailed introduction: 1. Solution to network problems: You can choose a different network, and then log in to the software again to try. 2. Solution to version problems: Users can download the latest version of this software from the official website. 3. Solutions to copyright issues: Some Korean dramas are removed from the shelves due to copyright issues. You can choose other Korean dramas to watch.

Explorer.exe crashing in Windows 11 safe mode no longer occurs Explorer.exe crashing in Windows 11 safe mode no longer occurs Aug 30, 2023 pm 11:09 PM

Explorer.exe crashes in Safe Mode on Windows 11? Not anymore. Microsoft has just released a new patch to the Dev Channel, and while there are no new features in this release, many fixes and improvements are making their way into the Windows Insider program, including an annoying bug where Explorer.exe crashes in Safe Mode. Well, you can say goodbye to it now, at least in the Windows Insider Program. But as with all these updates, they will also be coming to live Windows servers. Fixed an issue that caused Explorer.exe to not work in safe mode. However, there are a few other fixes coming to File Explorer, so Microsoft is keen to get it working

See all articles