php教程 PHP开发 Zend Framework 튜토리얼의 애플리케이션 사용 예에 ​​대한 자세한 설명

Zend Framework 튜토리얼의 애플리케이션 사용 예에 ​​대한 자세한 설명

Dec 27, 2016 pm 02:19 PM
zend framework

이 기사의 예에서는 Zend Framework 튜토리얼의 애플리케이션 사용법을 설명합니다. 참고할 수 있도록 모든 사람과 공유하세요. 자세한 내용은 다음과 같습니다.

Zend_Application은 Zend Framework의 핵심 구성 요소입니다. Zend_Application은 Zend Framework 애플리케이션에 대한 기본 기능을 제공하며 프로그램의 진입점입니다. 주요 기능은 PHP 환경 로드 및 구성(자동 로드 포함)과 애플리케이션 부팅의 두 가지입니다.

일반적으로 Zend_Application 생성자는 구성 옵션을 통해 구성되지만 사용자 지정 방법을 사용하여 완전히 구성할 수도 있습니다. 아래에는 두 가지 사용 사례가 있습니다.

Zend_Application 구성 옵션

생성자:

/**
 * Constructor
 *
 * Initialize application. Potentially initializes include_paths, PHP
 * settings, and bootstrap class.
 *
 * @param string          $environment
 * @param string|array|Zend_Config $options String path to configuration file, or array/Zend_Config of configuration options
 * @throws Zend_Application_Exception When invalid options are provided
 * @return void
 */
public function __construct($environment, $options = null)
{
  $this->_environment = (string) $environment;
  require_once 'Zend/Loader/Autoloader.php';
  $this->_autoloader = Zend_Loader_Autoloader::getInstance();
  if (null !== $options) {
    if (is_string($options)) {
      $options = $this->_loadConfig($options);
    } elseif ($options instanceof Zend_Config) {
      $options = $options->toArray();
    } elseif (!is_array($options)) {
      throw new Zend_Application_Exception('Invalid options provided; must be location of config file, a config object, or an array');
    }
    $this->setOptions($options);
  }
}
로그인 후 복사

Zend_Application 구성 방법

1. 구성 파일 사용
2. >

공통 구성 옵션

Zend Framework 튜토리얼의 애플리케이션 사용 예에 ​​대한 자세한 설명

참고:

옵션 이름은 대소문자를 구분하지 않습니다.

Zend_응용 방법

Zend Framework 튜토리얼의 애플리케이션 사용 예에 ​​대한 자세한 설명

Zend Framework 튜토리얼의 애플리케이션 사용 예에 ​​대한 자세한 설명

Zend Framework 튜토리얼의 애플리케이션 사용 예에 ​​대한 자세한 설명

구성 예:

기본값:

// Create application, bootstrap, and run
$application = new Zend_Application(
  APPLICATION_ENV,
  APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
      ->run();
로그인 후 복사
소스 코드

<?php
class Zend_Application
{  /**
   * Constructor
   *
   * Initialize application. Potentially initializes include_paths, PHP
   * settings, and bootstrap class.
   *
   * @param string          $environment
   * @param string|array|Zend_Config $options String path to configuration file, or array/Zend_Config of configuration options
   * @throws Zend_Application_Exception When invalid options are provided
   * @return void
   */
  public function __construct($environment, $options = null)
  {
    $this->_environment = (string) $environment;
    require_once &#39;Zend/Loader/Autoloader.php&#39;;
    $this->_autoloader = Zend_Loader_Autoloader::getInstance();
    if (null !== $options) {
      if (is_string($options)) {
        $options = $this->_loadConfig($options);
      } elseif ($options instanceof Zend_Config) {
        $options = $options->toArray();
      } elseif (!is_array($options)) {
        throw new Zend_Application_Exception(&#39;Invalid options provided; must be location of config file, a config object, or an array&#39;);
      }
      $this->setOptions($options);
    }
  }
  /**
   * Retrieve current environment
   *
   * @return string
   */
  public function getEnvironment()
  {
    return $this->_environment;
  }
  /**
   * Retrieve autoloader instance
   *
   * @return Zend_Loader_Autoloader
   */
  public function getAutoloader()
  {
    return $this->_autoloader;
  }
  /**
   * Set application options
   *
   * @param array $options
   * @throws Zend_Application_Exception When no bootstrap path is provided
   * @throws Zend_Application_Exception When invalid bootstrap information are provided
   * @return Zend_Application
   */
  public function setOptions(array $options)
  {
    if (!empty($options[&#39;config&#39;])) {
      if (is_array($options[&#39;config&#39;])) {
        $_options = array();
        foreach ($options[&#39;config&#39;] as $tmp) {
          $_options = $this->mergeOptions($_options, $this->_loadConfig($tmp));
        }
        $options = $this->mergeOptions($_options, $options);
      } else {
        $options = $this->mergeOptions($this->_loadConfig($options[&#39;config&#39;]), $options);
      }
    }
    $this->_options = $options;
    $options = array_change_key_case($options, CASE_LOWER);
    $this->_optionKeys = array_keys($options);
    if (!empty($options[&#39;phpsettings&#39;])) {
      $this->setPhpSettings($options[&#39;phpsettings&#39;]);
    }
    if (!empty($options[&#39;includepaths&#39;])) {
      $this->setIncludePaths($options[&#39;includepaths&#39;]);
    }
    if (!empty($options[&#39;autoloadernamespaces&#39;])) {
      $this->setAutoloaderNamespaces($options[&#39;autoloadernamespaces&#39;]);
    }
    if (!empty($options[&#39;autoloaderzfpath&#39;])) {
      $autoloader = $this->getAutoloader();
      if (method_exists($autoloader, &#39;setZfPath&#39;)) {
        $zfPath  = $options[&#39;autoloaderzfpath&#39;];
        $zfVersion = !empty($options[&#39;autoloaderzfversion&#39;])
              ? $options[&#39;autoloaderzfversion&#39;]
              : &#39;latest&#39;;
        $autoloader->setZfPath($zfPath, $zfVersion);
      }
    }
    if (!empty($options[&#39;bootstrap&#39;])) {
      $bootstrap = $options[&#39;bootstrap&#39;];
      if (is_string($bootstrap)) {
        $this->setBootstrap($bootstrap);
      } elseif (is_array($bootstrap)) {
        if (empty($bootstrap[&#39;path&#39;])) {
          throw new Zend_Application_Exception(&#39;No bootstrap path provided&#39;);
        }
        $path = $bootstrap[&#39;path&#39;];
        $class = null;
        if (!empty($bootstrap[&#39;class&#39;])) {
          $class = $bootstrap[&#39;class&#39;];
        }
        $this->setBootstrap($path, $class);
      } else {
        throw new Zend_Application_Exception(&#39;Invalid bootstrap information provided&#39;);
      }
    }
    return $this;
  }
  /**
   * Retrieve application options (for caching)
   *
   * @return array
   */
  public function getOptions()
  {
    return $this->_options;
  }
  /**
   * Is an option present?
   *
   * @param string $key
   * @return bool
   */
  public function hasOption($key)
  {
    return in_array(strtolower($key), $this->_optionKeys);
  }
  /**
   * Retrieve a single option
   *
   * @param string $key
   * @return mixed
   */
  public function getOption($key)
  {
  }
  /**
   * Merge options recursively
   *
   * @param array $array1
   * @param mixed $array2
   * @return array
   */
  public function mergeOptions(array $array1, $array2 = null)
  {
    if (is_array($array2)) {
      foreach ($array2 as $key => $val) {
        if (is_array($array2[$key])) {
          $array1[$key] = (array_key_exists($key, $array1) && is_array($array1[$key]))
                 ? $this->mergeOptions($array1[$key], $array2[$key])
                 : $array2[$key];
        } else {
          $array1[$key] = $val;
        }
      }
    }
    return $array1;
  }
  /**
   * Set PHP configuration settings
   *
   * @param array $settings
   * @param string $prefix Key prefix to prepend to array values (used to map . separated INI values)
   * @return Zend_Application
   */
  public function setPhpSettings(array $settings, $prefix = &#39;&#39;)
  {
    foreach ($settings as $key => $value) {
      $key = empty($prefix) ? $key : $prefix . $key;
      if (is_scalar($value)) {
        ini_set($key, $value);
      } elseif (is_array($value)) {
        $this->setPhpSettings($value, $key . &#39;.&#39;);
      }
    }
    return $this;
  }
  /**
   * Set include path
   *
   * @param array $paths
   * @return Zend_Application
   */
  public function setIncludePaths(array $paths)
  {
    $path = implode(PATH_SEPARATOR, $paths);
    set_include_path($path . PATH_SEPARATOR . get_include_path());
    return $this;
  }
  /**
   * Set autoloader namespaces
   *
   * @param array $namespaces
   * @return Zend_Application
   */
  public function setAutoloaderNamespaces(array $namespaces)
  {
    $autoloader = $this->getAutoloader();
    foreach ($namespaces as $namespace) {
      $autoloader->registerNamespace($namespace);
    }
    return $this;
  }
  /**
   * Set bootstrap path/class
   *
   * @param string $path
   * @param string $class
   * @return Zend_Application
   */
  public function setBootstrap($path, $class = null)
  {
    // setOptions() can potentially send a null value; specify default
    // here
    if (null === $class) {
      $class = &#39;Bootstrap&#39;;
    }
    if (!class_exists($class, false)) {
      require_once $path;
      if (!class_exists($class, false)) {
        throw new Zend_Application_Exception(&#39;Bootstrap class not found&#39;);
      }
    }
    $this->_bootstrap = new $class($this);
    if (!$this->_bootstrap instanceof Zend_Application_Bootstrap_Bootstrapper) {
      throw new Zend_Application_Exception(&#39;Bootstrap class does not implement Zend_Application_Bootstrap_Bootstrapper&#39;);
    }
    return $this;
  }
  /**
   * Get bootstrap object
   *
   * @return Zend_Application_Bootstrap_BootstrapAbstract
   */
  public function getBootstrap()
  {
    if (null === $this->_bootstrap) {
      $this->_bootstrap = new Zend_Application_Bootstrap_Bootstrap($this);
    }
    return $this->_bootstrap;
  }
  /**
   * Bootstrap application
   *
   * @param null|string|array $resource
   * @return Zend_Application
   */
  public function bootstrap($resource = null)
  {
    $this->getBootstrap()->bootstrap($resource);
    return $this;
  }
  /**
   * Run the application
   *
   * @return void
   */
  public function run()
  {
    $this->getBootstrap()->run();
  }
  /**
   * Load configuration file of options
   *
   * @param string $file
   * @throws Zend_Application_Exception When invalid configuration file is provided
   * @return array
   */
  protected function _loadConfig($file)
  {
    $environment = $this->getEnvironment();
    $suffix   = pathinfo($file, PATHINFO_EXTENSION);
    $suffix   = ($suffix === &#39;dist&#39;)
           ? pathinfo(basename($file, ".$suffix"), PATHINFO_EXTENSION)
           : $suffix;
    switch (strtolower($suffix)) {
      case &#39;ini&#39;:
        $config = new Zend_Config_Ini($file, $environment);
        break;
      case &#39;xml&#39;:
        $config = new Zend_Config_Xml($file, $environment);
        break;
      case &#39;json&#39;:
        $config = new Zend_Config_Json($file, $environment);
        break;
      case &#39;yaml&#39;:
      case &#39;yml&#39;:
        $config = new Zend_Config_Yaml($file, $environment);
        break;
      case &#39;php&#39;:
      case &#39;inc&#39;:
        $config = include $file;
        if (!is_array($config)) {
          throw new Zend_Application_Exception(&#39;Invalid configuration file provided; PHP file does not return array value&#39;);
        }
        return $config;
        break;
      default:
        throw new Zend_Application_Exception(&#39;Invalid configuration file provided; unknown config type&#39;);
    }
    return $config->toArray();
  }
}
로그인 후 복사
이 기사가 PHP 프로그래밍에 종사하는 모든 사람에게 도움이 되기를 바랍니다.

Zend Framework 튜토리얼 및 관련 기사에 포함된 애플리케이션 사용 예에 ​​대한 자세한 설명을 보려면 PHP 중국어 웹사이트를 주목하세요!

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

<gum> : Bubble Gum Simulator Infinity- 로얄 키를 얻고 사용하는 방법
4 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
Nordhold : Fusion System, 설명
1 몇 달 전 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora : 마녀 트리의 속삭임 - Grappling Hook 잠금 해제 방법
4 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
<exp exp> 모호한 : 원정 33- 완벽한 크로마 촉매를 얻는 방법
2 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

PHP와 함께 Zend Framework 사용: 빠른 시작 가이드 PHP와 함께 Zend Framework 사용: 빠른 시작 가이드 Jun 21, 2023 am 08:58 AM

PHP와 함께 ZendFramework 사용: 빠른 시작 가이드 ZendFramework는 강력하고 쉽게 확장 가능한 오픈 소스 PHP 기반 웹 애플리케이션 프레임워크입니다. ZendFramework에는 효율적인 웹 애플리케이션을 구축하는 데 도움이 되는 유용한 구성 요소가 많이 포함되어 있습니다. 이 기사에서는 PHP에서 ZendFramework를 사용하여 빠르게 시작하는 방법을 소개합니다. ZendFramewo 설치

Zend Framework 미들웨어를 통한 효율적인 데이터베이스 쿼리 Zend Framework 미들웨어를 통한 효율적인 데이터베이스 쿼리 Jul 28, 2023 pm 01:13 PM

ZendFramework 미들웨어를 통한 효율적인 데이터베이스 쿼리 구현 소개 개발 과정에서 데이터베이스 쿼리는 피할 수 없는 부분입니다. 효율적인 데이터베이스 쿼리는 시스템 성능과 사용자 경험을 크게 향상시킬 수 있습니다. ZendFramework는 강력한 데이터베이스 작업 기능을 갖춘 널리 사용되는 PHP 프레임워크입니다. 이 기사에서는 ZendFramework 미들웨어를 통해 효율적인 데이터베이스 쿼리를 구현하는 방법을 소개하고 해당 코드 예제를 제공합니다. 1. ZendF 이해

Zend Framework 미들웨어: 전체 텍스트 검색 및 페이징 기능 구현 Zend Framework 미들웨어: 전체 텍스트 검색 및 페이징 기능 구현 Jul 30, 2023 pm 08:49 PM

ZendFramework는 개발자가 확장 가능한 고성능 PHP 애플리케이션을 신속하게 구축하는 데 도움이 되는 강력한 개발 프레임워크입니다. 그 중 미들웨어는 ZendFramework의 중요한 개념으로, 전체 텍스트 검색 및 페이징 기능을 구현하는 데 도움을 줄 수 있습니다. 이 기사에서는 ZendFramework에서 미들웨어를 사용하여 이 두 가지 기능을 구현하는 방법을 소개하고 코드 예제를 제공합니다. 1. 전체 텍스트 검색 기능 전체 텍스트 검색은 최신 응용 프로그램의 일반적인 기능 중 하나입니다.

Zend Framework 미들웨어: 애플리케이션에 OAuth 및 OpenID 로그인 지원을 추가합니다. Zend Framework 미들웨어: 애플리케이션에 OAuth 및 OpenID 로그인 지원을 추가합니다. Jul 28, 2023 pm 01:09 PM

ZendFramework 미들웨어: 애플리케이션에 OAuth 및 OpenID 로그인 지원 추가 사용자 인증은 오늘날의 인터넷 애플리케이션에서 중요한 기능입니다. 더 나은 사용자 경험과 보안을 제공하기 위해 많은 애플리케이션은 OAuth 및 OpenID와 같은 타사 로그인 서비스를 통합하기로 선택합니다. ZendFramework에서는 미들웨어를 통해 애플리케이션에 OAuth 및 OpenID 로그인 지원을 쉽게 추가할 수 있습니다. 먼저 Ze를 설치해야 합니다.

Zend Framework 미들웨어: 이메일 알림 및 메시지 푸시 기능 제공 Zend Framework 미들웨어: 이메일 알림 및 메시지 푸시 기능 제공 Jul 29, 2023 pm 08:29 PM

ZendFramework 미들웨어: 이메일 알림 및 메시지 푸시 기능 제공 소개: 인터넷의 발전과 스마트폰의 인기로 인해 이메일 알림 및 메시지 푸시는 현대 소프트웨어 개발에서 일반적으로 사용되는 기능 중 하나가 되었습니다. ZendFramework에서는 미들웨어를 사용하여 이메일 알림 및 메시지 푸시 기능을 구현할 수 있습니다. 이 기사에서는 ZendFramework 미들웨어를 사용하여 이메일 알림 및 메시지 푸시를 구현하는 방법을 소개하고 해당 코드 예제를 제공합니다. 1. 준비 작업

Zend Framework 미들웨어: 웹 애플리케이션에 소셜 로그인 기능 추가 Zend Framework 미들웨어: 웹 애플리케이션에 소셜 로그인 기능 추가 Jul 28, 2023 pm 07:21 PM

ZendFramework는 확장 가능한 웹 애플리케이션을 구축하기 위한 많은 강력한 도구와 구성 요소를 제공하는 PHP 기반의 오픈 소스 프레임워크입니다. 이 기사에서는 ZendFramework의 미들웨어를 사용하여 웹 애플리케이션에 소셜 로그인 기능을 추가하는 방법을 소개합니다. 미들웨어는 요청이 애플리케이션에 들어오기 전이나 후에 실행되는 코드입니다. 이를 통해 개발자는 요청 처리 프로세스를 사용자 정의하고 확장할 수 있습니다. ZendFramework는 유연한 방법을 제공합니다.

CodeIgniter와 Zend Framework: ERP 시스템 개발에 어떤 프레임워크가 더 좋습니까? CodeIgniter와 Zend Framework: ERP 시스템 개발에 어떤 프레임워크가 더 좋습니까? Jun 19, 2023 am 08:53 AM

ERP 시스템을 개발하기로 결정했다면 적합한 프레임워크를 선택하는 것이 중요합니다. 여기서는 ERP 시스템 개발에 더 적합한 프레임워크를 찾는 데 도움이 되도록 두 가지 PHP 프레임워크인 CodeIgniter와 ZendFramework를 비교해 보겠습니다. CodeIgniter와 ZendFramework는 널리 사용되는 PHP 프레임워크입니다. 둘 다 많은 기능을 제공하며 확장 및 유지 관리가 가능합니다. 그러나 이 두 프레임워크는 일부 측면에서 크게 다르며 일부 애플리케이션에 더 적합합니다.

Zend Framework 미들웨어: 애플리케이션에 Alipay 및 WeChat 결제 기능 추가 Zend Framework 미들웨어: 애플리케이션에 Alipay 및 WeChat 결제 기능 추가 Jul 28, 2023 pm 08:01 PM

ZendFramework 미들웨어: 애플리케이션에 Alipay 및 WeChat 결제 기능 추가 소개: 모바일 결제의 인기로 인해 Alipay 및 WeChat 결제는 많은 애플리케이션에서 필수적인 결제 방법이 되었습니다. 이 기사에서는 ZendFramework 미들웨어를 사용하여 Alipay 및 WeChat 결제 기능을 애플리케이션에 추가하는 방법을 소개합니다. 이 기사를 공부하면 미들웨어를 사용하여 결제 프로세스를 단순화하고 실제 프로젝트에 적용하는 방법을 배울 수 있습니다. 1. 준비 시작하기 전에,

See all articles