0

I am currently dabbling in Magento and I want know how I can create a blank Hello World file whilst still including header, footer etc. I have read How to create a simple 'Hello World' module in Magento? - however I feel that this is too much for a static page.

I want to create www.site.com/magentolocation/helloworld.php

I want a blank PHP file and rather go down the module and MVC approach can I not just do:

<?php
include magconfig;
mag->header;

echo 'hello world' // or other static html

mag->footer;
?>

Simple.

Community
  • 1
  • 1
TheBlackBenzKid
  • 26,324
  • 41
  • 139
  • 209
  • 1
    OK so far update - I did this from Admin -> CMS -> and put the URL key as "helloworld.php" and presto it works. However it is not via an echo or PHP just static HTML. – TheBlackBenzKid Dec 19 '11 at 10:18

2 Answers2

4

http://alanstorm.com/magento_controller_hello_world http://alanstorm.com/layouts_blocks_and_templates

You want to use a template file which is a .phtml file which will let you write PHP and html, but to access it you'll have to set up a Controller. Magento is a beast which must be learned properly. There is no correct way to "escape" from the framework - you are supposed to work within the framework.

Max
  • 8,671
  • 4
  • 33
  • 46
  • I understand that and I agree and appreciate your response; but there must be someway to create a PHP file in the root along with index.php which does the same and has a middle bit which can server what is needed?? – TheBlackBenzKid Dec 19 '11 at 12:16
  • No - you have to set this up using the layout xml. – Max Dec 19 '11 at 12:25
1

I'm sure there might be a prettier way but here is a quick snippet for you:

<?php

require_once ('app/Mage.php');
umask(0);
Mage::app('default');
Mage::getSingleton('core/session', array('name' => 'frontend'));
$Block = Mage::getSingleton('core/layout');
$head = $Block->createBlock('Page/Html_Head');
$head->addCss('css/styles.css');
$head->addJs('prototype/prototype.js');
$header = $Block->createBlock('Page/Html_Header');
$header->setTemplate('page/html/header.phtml');
$footer = $Block->createBlock('Page/Html_Footer');
$footer->setTemplate('page/html/footer.phtml');

?>
<html>
<head>
<?php echo $head->getCssJsHtml(); ?>
</head>
<body>
<?php

    echo $header->toHTML();

    echo 'hello world';

    echo $footer->toHTML();
?>
</body>
</html>
user487772
  • 8,800
  • 5
  • 47
  • 72
  • 1
    This looks like it would technically work but like I said before, this is not the smart way of approaching learning Magento. It is very error prone to work this way. – Max Dec 19 '11 at 12:50
  • 1
    I agree, but I am not really up for learning the framework as it seems to complex and constrained. It reminds me of working with IBM WebSphere Commerce. – TheBlackBenzKid Dec 19 '11 at 12:54
  • 1
    This quite simply a quick hack fix - and simply a brilliant piece of code with some minor tweaks needed - much appreciated. @Max there are times when you need this - why boat hundreds of modules and XML libraries for a Hello world - there is just no need. – TheBlackBenzKid Dec 19 '11 at 13:15
  • @TheBlackBenzKid - agreed, but for a Hello world, don't use magento –  Dec 19 '11 at 13:39
  • 1
    I agree with Max. The purpose of an Hello World is to get an introduction to the underlying system and in Magento that is all about modules and config files and MVC patterns. Trying to use a standalone file teaches you nothing about any of those things. – clockworkgeek Dec 19 '11 at 14:23
  • 1
    I am not after learning anything. It was a quick fix and this is still a learning curve as you can see the declarations to pull the relevant objects and modules. Irrelevant comment via @clockworkgeek – TheBlackBenzKid Dec 19 '11 at 14:41
  • so clockworkgeek's comment is irrelevant and Dick Laurent's code is brilliant... (no offense Dick, I'm sure the code is working, but that's not what I call brilliant, and I don't think it is possible to produce brilliant code for this question) lol – OSdave Dec 19 '11 at 18:33