Zend Framework Tutorial Resource (resources) Usage examples detailed _php example

Source: Internet
Author: User
Tags zend zend framework getbootstrap

This example describes the resource (resources) usage of the Zend Framework tutorial. Share to everyone for your reference, specific as follows:

Zend_application_resource_resource

Zend_application_bootstrap_resourcebootstrapper is the interface used by the bootstrap class to load the registered resource plug-in.
Zend_application_resource_resource is a resource plug-in interface.
Zend_application_resource_resource are usually used to implement the zend_application_bootstrap_resourcebootstrapper of the boot class.

A resource plug-in is a configurable, preloaded interface that can initialize resources through a policy pattern.

Zend_application_resource_resource Interface

method return
Value Parameters Description
__construct ($options = null) void
  • $options : optional . Configure the resource.

 

setbootstrap (zend_application_bootstrap_bootstrapper $bootstrap) < span class= "classname" Lucida Console ', monospace, fixed; Color:rgb (0,0,0); Font-weight:bold ">zend_application_resource_resource
  • $bootstrap : required . Initializes the resource's parent bootstrap class

  •  

    getbootstrap () zend_application_bootstrap_bootstrapper n/a


    SetOptions (Array $options) Zend_application_resource_resource
    • $options: must fill . Configuration options.

    GetOptions () Array N/A

    Init () Mixed N/A

    Use Policy mode: Run, initialize resources.


    zend_application_resource_resourceabstract

    Zend_application_resource_resourceabstract is an abstract class that implements the Zend_application_resource_resource interface and provides a convenient way to create a custom plug-in resource.

    Note: This abstract class does not implement the Init () method, which can be inherited using this abstract class to customize the implementation of the Init method.

    Zend_application_resource_resourceabstract Methods

    method return
    Value Parameters Description
    __construct ($options = null) void
    • $options : optional . Configuration resource

     

    setbootstrap (zend_application_bootstrap_bootstrapper $bootstrap) < span class= "classname" Lucida Console ', monospace, fixed; Color:rgb (0,0,0); Font-weight:bold ">zend_application_resource_resourceabstract
    • $bootstrap : required .  

     

    getbootstrap () zend_application_bootstrap_bootstrapper n/a

     

    SetOptions (Array $options) Zend_application_resource_resourceabstract
    • $options: must fill .

    GetOptions () Array N/A


    Resource Name

    One of the problems that arises when registering a plug-in resource is how you should boot the class from the parent. There are three different mechanisms that can be used, depending on how you configure the bootstrap and its plugin resources.

    First, if your plugin name definition contains a prefix path, you can pass their "short name"-that is, part of the class name. For example, the short name for Class "Zend_application_resource_view" is "View" if the prefix path "Zend_application_resource" is registered. You may register them with the full or short name of the class:

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

    You can use short names to boot resources and get:

    $bootstrap->bootstrap (' view ');
    $view = $bootstrap->getresource (' View ');
    
    

    Second, if there is no definition of a matching plugin path, you may still use the full name of the resource class. In this case, you can refer to the full class name of the resource using the following:

    $app = new Zend_application (application_env, Array (
      ' resources ' => Array (
        //This'll load the standard ' View ')  Resource:
        ' View ' => Array (),
        //While this loads a resource with a specific class name:
        ' My_resource_view ' => Array (),))
    ;
    
    

    Guide resources and how to get them

    $bootstrap->bootstrap (' My_resource_view ');
    $view = $bootstrap->getresource (' My_resource_view ');
    

    This brings us to the third option. You can specify a specific name and register yourself as a given resource class. This can be done by adding the public $_explicittype string value through the resource plug-in class, which will be used to specify the boot plug-in resource. As an example, let's define our own view classes:

    Class My_resource_view extends Zend_application_resource_resourceabstract
    {public
      $_explicittype = ' My_ View ';
      Public function init ()
      {
        //Do some initialization ...
      }
    }
    
    

    Then we can boot the resource or get it by its name "My_view":

    $bootstrap->bootstrap (' My_view ');
    $view = $bootstrap->getresource (' My_view ');
    
    

    You can use these different naming methods to overwrite existing resources, add your own, mix I with multiple resources to achieve complex initialization, and so on.

    More interested in Zend related content readers can view the site topics: "The introduction of the Zend Framework frame", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Course", "PHP object-oriented Programming Program , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"

    I hope this article will help you with the PHP program design.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.