0

I have an external webpage say "test.php" and I have loaded the site header & footer block from the Magento framework to use as a header & footer in this external page. Everything is working fine except url links. This is what I have done so far:

include 'app/Mage.php';
Mage::app();

umask(0);
Mage::app()->loadArea('frontend');
Mage::getSingleton('core/session', array('name' => 'frontend'));
$layout = Mage::getSingleton('core/layout');

//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default');
$layout->generateXml()->generateBlocks();

//load header
$headBlock = $layout->getBlock('head');
$headerBlock = $layout->getBlock('header');
echo $headBlock->toHtml() . $headerBlock->toHtml();

// load footer
$footerBlock = $layout->getBlock('footer');
echo $footerBlock->toHtml();

The problem is url link generated at this page includes test.php in its base url.

Say I have a link "About Us". The url generated for this link in magento is "http://localhost/myapp/index.php/about.html" But url generated for the same link on test.php is "http://localhost/myapp/test.php/about.html".

How this can be resolved?

OR

Is there any other way to load theme's header and footer?

1 Answer 1

0

Add below lines to the first of your script:

$_SERVER['SCRIPT_NAME'] = str_replace(basename(__FILE__), 'index.php',        $_SERVER['SCRIPT_NAME']);
$_SERVER['SCRIPT_FILENAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_FILENAME']);

the final script will looks like:

include 'app/Mage.php';

//Added
$_SERVER['SCRIPT_NAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_NAME']);
$_SERVER['SCRIPT_FILENAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_FILENAME']);

Mage::app();

umask(0);
Mage::app()->loadArea('frontend');
Mage::getSingleton('core/session', array('name' => 'frontend'));
$layout = Mage::getSingleton('core/layout');

//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default');
$layout->generateXml()->generateBlocks();

//load header
$headBlock = $layout->getBlock('head');
$headerBlock = $layout->getBlock('header');
echo $headBlock->toHtml() . $headerBlock->toHtml();

// load footer
$footerBlock = $layout->getBlock('footer');
echo $footerBlock->toHtml();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.