I want to make a little Zend app that runs along side our Magento (Enterprise) install. Can I use the existing Zend code included with Magento? Or do I need to have another separate copy of Zend?
I am afraid that Varien has probably messed with the framework code. Just looking it appears they have commented out all require() statements, which is throwing lots of errors (obviously). The Zend AutoLoader won't work, at any rate. Is there a way to use the Varien AutoLoader instead?
I don't particularly want to import another framework (3000+ files) into our project if I can avoid it.
Thanks!
EDIT:
Here is my dir structure:
/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
Here is the code I am trying (/localsite/fbtest/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();
Here is the error:
Fatal error: Class 'Zend_Loader_Autoloader' not found in C:\xampp\htdocs\localsite\products\lib\Zend\Application.php on line 81
Here is the include_path:
C:\xampp\htdocs\localsite\products\lib\Zend;.;C:\php\pear
And here is where AutoLoader should be included (in /products/lib/Zend/Application.php):
#require_once 'Zend/Loader/Autoloader.php';
$this->_autoloader = Zend_Loader_Autoloader::getInstance();
^^^ see that '#' where the require_once is commented out? I think that's a change Varien made which breaks the Framework, no? It appears to be why it's not working form me, at least? How can I get around this and include all of the commented out includes??
Thanks again
add magento's library folder to include path in 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());
But with this approach you can't use latest ZF version. So separate install is my choice.
autoloader works, easy way here is to place original Zend/Loader/ into your application library, or include all required autoloader classes manually(just 3: loader, autoloader, Zend_Exception)
Here is my full projectName/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
}
This is how your /localsite/fbtest/public/index.php may look:
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With