2

In following File, there is a file "reload.php"

But i want to use "myajaxcart.phtml" in Magento, How ??

Is it possible to use .phtml there, as magento doesn't allow direct access to .phtml files ??

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script>
var auto_refresh = setInterval(
function()
{
$('#loaddiv').fadeOut('slow').load('reload.php').fadeIn("slow");
}, 200);
</script>

I want like this :

$('#loaddiv').fadeOut('slow').load('myajaxcart.phtml').fadeIn("slow");

Thanks in Advance.

2

Using a standalone PHP file is not right way. You should be following the MVC structure of Magento.

AOE made a module that loosely does what you need it to do (ie. render out a block to be used for AJAX calls). It opens a little bit of a minefield in terms of security as potentially any block can be loaded, but you can add some appropriate filters to prevent issues.

There is a repo here, https://github.com/fbrnc/Aoe_Static

The basic principle relies on a simple block of code within the main controller,

$this->loadLayout();
$layout = $this->getLayout();

$requestedBlockNames = $this->getRequest()->getParam('getBlocks');
if (is_array($requestedBlockNames)) {
  foreach ($requestedBlockNames as $id => $requestedBlockName) {
    $tmpBlock = $layout->getBlock($requestedBlockName);
    if ($tmpBlock) {
      $response['blocks'][$id] = $tmpBlock->toHtml();
    } else {
      $response['blocks'][$id] = 'BLOCK NOT FOUND';
    }
  }
}
$this->getResponse()->setBody(Zend_Json::encode($response));
3

Magento is implemented with the MVC pattern, this means Models, Views and Controllers are separated. All .phtml files in Magento are party of the view and can not be directly accessed, only controllers are accessible from outside, which themselfes render the view including the .phtml file.

So for your case create a simple controller, if there is not already one who renders the myajaxcart.phtml. If you're new in implementing controllers and associating views have a look in the layout.xml tutorial on magentocommerce.com

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.