0

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.

1

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.

  • I have key disabled from admin urls. Also, I am extending core magento shipment, so, I don't have to copy whole bunch of code to custom module. If there is no way to get content as mentioned in the question, then, this is the last option. – Damodar Bashyal Nov 18 '16 at 6:26
  • 1
    Try following: open login page using curl_exec. Read the form key, submit the form with username, password and form key. Use curl and specify cookie file as curl option. Then go to your page using the same cookie file. – Moshe Shperling Nov 18 '16 at 7:14
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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