添加 magento 的库文件夹以在 index.php 中包含路径:
//define shortcut for DIRECTORY_SEPARATOR
defined('DS') || define('DS', DIRECTORY_SEPARATOR);
//define base bath obtainable throughout the whole application
defined('BASE_PATH')
|| define('BASE_PATH', realpath(dirname(__FILE__) . DS . '..' . DS . 'basedir' . DS));
//define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', BASE_PATH . DS . 'app');
//set include path to libraries
set_include_path(BASE_PATH . DS . 'library' . PATH_SEPARATOR . MAGENTO_DIR . DS . 'lib' . PATH_SEPARATOR . get_include_path());
但是通过这种方法,您不能使用最新的 ZF 版本。所以单独安装是我的选择。
自动加载器可以工作,这里简单的方法是将原始 Zend/Loader/ 放入您的应用程序库中,或者手动包含所有必需的自动加载器类(只有 3 个:加载器、自动加载器、Zend_Exception)
这是我的完整项目名称/public/index.php:
if (get_magic_quotes_gpc()) {
function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
$_POST = array_map('stripslashes_deep', $_POST);
$_GET = array_map('stripslashes_deep', $_GET);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
$_REQUEST = array_map('stripslashes_deep', $_REQUEST);
}
//define shortcut for DIRECTORY_SEPARATOR
defined('DS') || define('DS', DIRECTORY_SEPARATOR);
//define base bath obtainable throughout the whole application
defined('BASE_PATH')
|| define('BASE_PATH', realpath(dirname(__FILE__) . DS . '..' . DS . 'basedir'));
//define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', BASE_PATH . DS . 'app');
//set include path to libraries
set_include_path(BASE_PATH . DS . 'library' . PATH_SEPARATOR . get_include_path());
//bootstrap, and run application
try {
require_once 'Zend/Application.php';
//create application and configure it.
$application = new Zend_Application(
getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production',
array('config' => array(APPLICATION_PATH . DS . 'configs' . DS . 'application.ini'))
);
//run application
$application->bootstrap()->run();
} catch (Exception $e) {
//here was logging logic
}
这就是您的 /localsite/fbtest/public/index.php 的外观:
if (get_magic_quotes_gpc()) {
function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
$_POST = array_map('stripslashes_deep', $_POST);
$_GET = array_map('stripslashes_deep', $_GET);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
$_REQUEST = array_map('stripslashes_deep', $_REQUEST);
}
//define shortcut for DIRECTORY_SEPARATOR
defined('DS') || define('DS', DIRECTORY_SEPARATOR);
//define base bath obtainable throughout the whole application
//keep your libraries and application out of public directory
defined('BASE_PATH')
|| define('BASE_PATH', realpath(dirname(__FILE__) . DS . '..' . DS . 'basedir'));
//define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', BASE_PATH . DS . 'application');
//if index.php in /localsite/fbtest/public/
defined('MAGENTO_PATH')
|| define('MAGENTO_PATH', realpath(dirname(__FILE__) . DS . '..' . DS . '..' . DS . 'products'));
//set include path to libraries
//noticed magento library added?
set_include_path(BASE_PATH . DS . 'library' . PATH_SEPARATOR . MAGENTO_PATH . DS . 'lib' . PATH_SEPARATOR . get_include_path());
//bootstrap, and run application
try {
require_once 'Zend/Application.php';
require_once 'Zend/Loader.php';
require_once 'Zend/Loader/Autoloader.php';
require_once 'Zend/Exception.php';
//create application and configure it.
$application = new Zend_Application(
getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production',
array('config' => array(APPLICATION_PATH . DS . 'configs' . DS . 'application.ini'))
);
//run application
$application->bootstrap()->run();
} catch (Exception $e) {
//here was logging logic
}