Question

I am trying to get output of a page in admin from a helper file which I need for a cron to convert it into pdf and email:

$html = file_get_contents('http://dltr.org/index.php/admin/dltrpdf_sales_shipment/index/shipment_id/65')

But, I get login page html, as it's a secure admin page. I also tried this PHPCurl but it didn't work. I still got login page html.

Is there any internal function available in Magento that can emulate admin page load and return correct html output (source code)?

FYI, I am using Magento ver. 1.14.2.4.

Was it helpful?

Solution

In order to get any page in admin you need to have key parameter in the url. You receive the key at the login.

You can write a custom module with output that you need from that admin page.

OTHER TIPS

Technically, using file_get_contents() connecting from a different computer and is not under the same session as your browser. Therefore you are failing authentication.

Instead, look into exporting the block as HTML:

$block = $this->getLayout()->createBlock(
    'some/block', 
    'block_name', 
    array()
);

$html = $block->toHtml();

The code above is written for a controller, so you would need a little extra work to get the Layout object from a helper.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top