Zend framework 是否可以使用Magento';在另一个应用程序中是否存在/包含Zend框架?

Zend framework 是否可以使用Magento';在另一个应用程序中是否存在/包含Zend框架?,zend-framework,magento,Zend Framework,Magento,我想做一个小Zend应用程序,在我们的Magento(企业版)安装中运行。我可以使用Magento附带的现有Zend代码吗?或者我需要另一份Zend吗 我担心Varien可能弄乱了框架代码。只要看一下,他们似乎已经注释掉了所有require()语句,这会抛出很多错误(显然)。Zend自动加载器无论如何都不会工作。有没有办法改用Varien自动加载器 如果可以避免的话,我并不特别想将另一个框架(3000多个文件)导入到我们的项目中 谢谢 编辑: 以下是我的目录结构: /localsite/ --

我想做一个小Zend应用程序,在我们的Magento(企业版)安装中运行。我可以使用Magento附带的现有Zend代码吗?或者我需要另一份Zend吗

我担心Varien可能弄乱了框架代码。只要看一下,他们似乎已经注释掉了所有require()语句,这会抛出很多错误(显然)。Zend自动加载器无论如何都不会工作。有没有办法改用Varien自动加载器

如果可以避免的话,我并不特别想将另一个框架(3000多个文件)导入到我们的项目中

谢谢

编辑:

以下是我的目录结构:

/localsite/ -- root
/localsite/products -- Magento install
/localsite/products/lib/Zend --Zend in Mage folder
/localsite/fbtest -- my Zend Framework app root
/localsite/fbtest/application -- my Zend Framework app
下面是我正在尝试的代码(/localsite/fbtest/public/index.php):

以下是包含路径:

C:\xampp\htdocs\localsite\products\lib\Zend;.;C:\php\pear
这里应该包括AutoLoader(在/products/lib/Zend/Application.php中):

^^^看到注释掉require_once的“#”了吗?我认为这是瓦里恩做出的改变,打破了框架,不是吗?至少,这就是为什么它对我不起作用的原因?我怎样才能绕过这一点,并包括所有已注释掉的内容


再次感谢

将magento的库文件夹添加到index.php中的路径:

<?php
define('DS', DIRECTORY_SEPARATOR);

defined('APPLICATION_PATH')
  || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

defined('APPLICATION_ENV')
  || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

set_include_path(implode(PATH_SEPARATOR, array(
  BASE_PATH . DS . 'products' . DS . 'lib' . DS . 'Zend',
  get_include_path(),
)));

require_once('../../products/lib/Zend/Application.php');

$application = new Zend_Application(
  APPLICATION_ENV,
  APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
        ->run();
//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());
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
}
<?php
define('DS', DIRECTORY_SEPARATOR);

defined('APPLICATION_PATH')
  || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

defined('APPLICATION_ENV')
  || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

set_include_path(implode(PATH_SEPARATOR, array(
  BASE_PATH . DS . 'products' . DS . 'lib',
  '.',
)));

require_once 'Zend/Loader.php';

require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();

require_once APPLICATION_PATH.'/Bootstrap.php';

$application = new Zend_Application(
  APPLICATION_ENV,
  APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
    ->run();
但是使用这种方法,您不能使用最新的ZF版本。因此,我选择单独安装。

autoloader工作,简单的方法是将原始的Zend/Loader/放入应用程序库,或者手动包含所有必需的autoloader类(仅3个:Loader、autoloader、Zend_例外)

这是我的完整项目名/public/index.php:

<?php
define('DS', DIRECTORY_SEPARATOR);

defined('APPLICATION_PATH')
  || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

defined('APPLICATION_ENV')
  || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

set_include_path(implode(PATH_SEPARATOR, array(
  BASE_PATH . DS . 'products' . DS . 'lib' . DS . 'Zend',
  get_include_path(),
)));

require_once('../../products/lib/Zend/Application.php');

$application = new Zend_Application(
  APPLICATION_ENV,
  APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
        ->run();
//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());
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
}
<?php
define('DS', DIRECTORY_SEPARATOR);

defined('APPLICATION_PATH')
  || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

defined('APPLICATION_ENV')
  || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

set_include_path(implode(PATH_SEPARATOR, array(
  BASE_PATH . DS . 'products' . DS . 'lib',
  '.',
)));

require_once 'Zend/Loader.php';

require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();

require_once APPLICATION_PATH.'/Bootstrap.php';

$application = new Zend_Application(
  APPLICATION_ENV,
  APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
    ->run();
以下是/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
}
我担心Varien可能弄乱了框架代码

我猜这会违反使用条款(除了一次剥离require_)

Zend_Autoloader在我看来应该可以正常工作。只需设置include路径,就可以了;)

更新:

我可以从您的代码中看出,您没有定义
BASE\u路径
常量。因此,未定义包含路径,无法加载
Zend\u Loader\u Autoloader
。如果include路径可以,那么可以编写
require_once'Zend/Loader/Autoloader.php'没有路径。此外,不需要使用
Zend_Loader
它已被弃用


您还包括
Zend_应用程序
而不是
加载程序
。为什么?唯一需要“硬代码”的类是autoloader,使用行
require_once“Zend/Loader/Autoloade.php”-没别的了。如果它不工作,您的include路径就混乱了

好吧,我明白了!带有Magento的Zend框架并没有真正崩溃。。。但是他们做的事情和平常有点不同

1) 当您使用Zend Loader启用“延迟加载”时,在Zend中注释掉require_once()语句是正常的。这是一个性能问题:

2) 但是,在Application.php和Loader.php类中注释掉它们是不正常的:

[在Zend_应用程序和Zend_Loader_Autoloader中保留]require_once()调用,因为没有它们这些类将失败

因此,答案是在启用Loader.php时自己添加3条缺失的require_once()语句。以下是我的新代码(在我的apps index.php中):


以下代码启用了在cli脚本中使用Zend Framework。Magento附带的Zend框架已用于cli脚本

// 1. point libPath to the <magento-root>/lib directory
$libPath=realpath(dirname(__FILE__).'../../../lib') ;

// 2. set the Zend-Framework include-path
set_include_path($libPath . PATH_SEPARATOR . get_include_path());

// 3. manual includes 

require_once 'Zend/Loader.php';
require_once 'Zend/Loader/Autoloader.php';

// 4. instantiate the autoloader
Zend_Loader_Autoloader::getInstance();
//1。将libPath指向/lib目录
$libPath=realpath(dirname(_文件__)。“../../../lib”);
// 2. 设置Zend框架包含路径
set_include_path($libPath.path_SEPARATOR.get_include_path());
// 3. 手册包括
需要一次'Zend/Loader.php';
需要_once'Zend/Loader/Autoloader.php';
// 4. 实例化自动加载器
Zend_Loader_Autoloader::getInstance();

这使您能够使用Zend_Http_客户端及其所有相关类。

感谢您的回答!但它不起作用。如果你想再看一次的话,我在问题中添加了更多信息。我在问题中添加了更多信息,只是设置包含路径不起作用。关于TOS的有趣的一点是。。。可惜这对我解决这个问题没有帮助。:)关于仍然需要Application.php的观点很好,我不再这样做了。