如上所述启用 Zend 扩展与包含您想要执行的 ZF 类无关。下载 ZF 并将其上传到public_html
文件夹中您喜欢的任何位置(如果某处尚不可用)。使用set_include_path()
和去!下面的示例代码:
<?php
// Define relative path to ZendFramework in public_html
define('ZF_PATH', '/../../../lib/php/zendframework');
// Define path to application directory
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define real path to ZendFramework if it's not yet included in include_path
if(!strpos(get_include_path(), 'zendframework'))
define('ZF_REAL_PATH', realpath(APPLICATION_PATH . ZF_PATH));
else define('ZF_REAL_PATH', '');
// Updating include_path
set_include_path(implode(PATH_SEPARATOR, array(ZF_REAL_PATH, get_include_path(),)));
// Done! the rest of the code might be unnecessary in your case.
require 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
$application->bootstrap()->run();
对于添加目录以包含路径的情况,这可能看起来有点复杂,但我认为这是 ZF 应用程序使用的最常见方式。