


Explication détaillée des exemples d'utilisation d'applications dans le didacticiel Zend Framework
L'exemple de cet article décrit l'utilisation de l'application du didacticiel Zend Framework. Partagez-le avec tout le monde pour votre référence, les détails sont les suivants :
Zend_Application est le composant principal de Zend Framework. Zend_Application fournit des fonctionnalités de base pour les applications Zend Framework et constitue le point d'entrée du programme. Ses fonctions principales sont au nombre de deux : charger et configurer l'environnement PHP (y compris le chargement automatique) et démarrer l'application.
Généralement, le constructeur Zend_Application est configuré via les options de configuration, mais il peut également être entièrement configuré à l'aide d'une méthode personnalisée. Vous trouverez ci-dessous deux cas d'utilisation.
Options de configuration de Zend_Application
Constructeur :
/** * 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); } }
Méthode de configuration de Zend_Application
1. Utiliser le fichier de configuration
Utiliser le tableau de configuration< 🎜. >
// 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 '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); } } /** * 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['config'])) { if (is_array($options['config'])) { $_options = array(); foreach ($options['config'] as $tmp) { $_options = $this->mergeOptions($_options, $this->_loadConfig($tmp)); } $options = $this->mergeOptions($_options, $options); } else { $options = $this->mergeOptions($this->_loadConfig($options['config']), $options); } } $this->_options = $options; $options = array_change_key_case($options, CASE_LOWER); $this->_optionKeys = array_keys($options); if (!empty($options['phpsettings'])) { $this->setPhpSettings($options['phpsettings']); } if (!empty($options['includepaths'])) { $this->setIncludePaths($options['includepaths']); } if (!empty($options['autoloadernamespaces'])) { $this->setAutoloaderNamespaces($options['autoloadernamespaces']); } if (!empty($options['autoloaderzfpath'])) { $autoloader = $this->getAutoloader(); if (method_exists($autoloader, 'setZfPath')) { $zfPath = $options['autoloaderzfpath']; $zfVersion = !empty($options['autoloaderzfversion']) ? $options['autoloaderzfversion'] : 'latest'; $autoloader->setZfPath($zfPath, $zfVersion); } } if (!empty($options['bootstrap'])) { $bootstrap = $options['bootstrap']; if (is_string($bootstrap)) { $this->setBootstrap($bootstrap); } elseif (is_array($bootstrap)) { if (empty($bootstrap['path'])) { throw new Zend_Application_Exception('No bootstrap path provided'); } $path = $bootstrap['path']; $class = null; if (!empty($bootstrap['class'])) { $class = $bootstrap['class']; } $this->setBootstrap($path, $class); } else { throw new Zend_Application_Exception('Invalid bootstrap information provided'); } } 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 = '') { 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 . '.'); } } 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 = 'Bootstrap'; } if (!class_exists($class, false)) { require_once $path; if (!class_exists($class, false)) { throw new Zend_Application_Exception('Bootstrap class not found'); } } $this->_bootstrap = new $class($this); if (!$this->_bootstrap instanceof Zend_Application_Bootstrap_Bootstrapper) { throw new Zend_Application_Exception('Bootstrap class does not implement Zend_Application_Bootstrap_Bootstrapper'); } 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 === 'dist') ? pathinfo(basename($file, ".$suffix"), PATHINFO_EXTENSION) : $suffix; switch (strtolower($suffix)) { case 'ini': $config = new Zend_Config_Ini($file, $environment); break; case 'xml': $config = new Zend_Config_Xml($file, $environment); break; case 'json': $config = new Zend_Config_Json($file, $environment); break; case 'yaml': case 'yml': $config = new Zend_Config_Yaml($file, $environment); break; case 'php': case 'inc': $config = include $file; if (!is_array($config)) { throw new Zend_Application_Exception('Invalid configuration file provided; PHP file does not return array value'); } return $config; break; default: throw new Zend_Application_Exception('Invalid configuration file provided; unknown config type'); } return $config->toArray(); } }

Outils d'IA chauds

Undresser.AI Undress
Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover
Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool
Images de déshabillage gratuites

Clothoff.io
Dissolvant de vêtements AI

AI Hentai Generator
Générez AI Hentai gratuitement.

Article chaud

Outils chauds

Bloc-notes++7.3.1
Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise
Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1
Puissant environnement de développement intégré PHP

Dreamweaver CS6
Outils de développement Web visuel

SublimeText3 version Mac
Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Utiliser ZendFramework avec PHP : Guide de démarrage rapide ZendFramework est un framework d'application Web open source basé sur PHP, puissant et facilement extensible. ZendFramework contient de nombreux composants utiles qui peuvent vous aider à créer des applications Web efficaces. Cet article explique comment utiliser ZendFramework en PHP pour vous aider à démarrer rapidement. Installer ZendFramewo

Implémenter des requêtes de base de données efficaces via le middleware ZendFramework Introduction Dans le processus de développement, les requêtes de base de données sont une partie inévitable. Une requête de base de données efficace peut améliorer considérablement les performances du système et l’expérience utilisateur. ZendFramework est un framework PHP largement utilisé avec de puissantes fonctions d'exploitation de bases de données. Cet article présentera comment implémenter des requêtes de base de données efficaces via le middleware ZendFramework et fournira des exemples de code correspondants. 1. Comprendre ZendF

ZendFramework Middleware : Ajout du support de connexion OAuth et OpenID aux applications L'authentification des utilisateurs est une fonctionnalité essentielle dans les applications Internet actuelles. Afin d'offrir une meilleure expérience utilisateur et une meilleure sécurité, de nombreuses applications choisissent d'intégrer des services de connexion tiers, tels que OAuth et OpenID. Dans ZendFramework, nous pouvons facilement ajouter la prise en charge de la connexion OAuth et OpenID à nos applications via un middleware. Tout d'abord, nous devons installer Ze

ZendFramework est un framework de développement puissant qui aide les développeurs à créer rapidement des applications PHP hautes performances et évolutives. Parmi eux, le middleware est un concept important dans ZendFramework, qui peut nous aider à implémenter des fonctions de recherche et de pagination en texte intégral. Cet article présentera comment utiliser le middleware dans ZendFramework pour implémenter ces deux fonctions et fournira des exemples de code. 1. Fonction de recherche en texte intégral La recherche en texte intégral est l'une des fonctions courantes dans les applications modernes.

ZendFramework est un framework open source basé sur PHP qui fournit de nombreux outils et composants puissants pour créer des applications Web évolutives. Cet article explique comment utiliser le middleware de ZendFramework pour ajouter une fonctionnalité de connexion sociale aux applications Web. Le middleware est un code exécuté avant ou après qu'une requête entre dans votre application. Il permet aux développeurs de personnaliser et d'étendre le processus de traitement des demandes. ZendFramework fournit un moyen flexible de

Middleware ZendFramework : Ajout des fonctions de paiement Alipay et WeChat aux applications Introduction : Avec la popularité des paiements mobiles, les paiements Alipay et WeChat sont devenus des méthodes de paiement incontournables dans de nombreuses applications. Cet article explique comment utiliser le middleware ZendFramework pour ajouter les fonctions de paiement Alipay et WeChat aux applications. En étudiant cet article, vous apprendrez à utiliser un middleware pour simplifier le processus de paiement et l'appliquer à vos projets réels. 1. Préparation Avant de commencer, vous

ZendFramework2 est un framework de programmation PHP populaire qui fournit une multitude de fonctions et de modules, permettant aux développeurs PHP de créer plus facilement des applications Web de haute qualité. Cet article présentera quelques opérations courantes de ZendFramework2 pour vous aider à mieux utiliser ce framework. Modèle MVC Dans ZendFramework2, le modèle Modèle-Vue-Contrôleur (MVC) est l'architecture la plus courante. Le modèle MVC est un

Lorsque vous décidez de développer un système ERP, le choix d’un framework adapté est crucial. Ici, nous comparerons les deux frameworks PHP CodeIgniter et ZendFramework pour vous aider à trouver un framework plus adapté au développement de votre système ERP. CodeIgniter et ZendFramework sont des frameworks PHP populaires. Ils offrent tous de nombreuses fonctionnalités et sont extensibles et maintenables. Cependant, ces deux frameworks diffèrent considérablement sur certains aspects et sont plus adaptés à certaines applications.
