views:

134

answers:

2

Hi all,

I'm trying to figure out how exactly Magento's dispatching system works.

I want to dispatch a certain part of the layout (e.g. the body) from outside the application directory.

What i have so far;

<?php
$app          = Mage::app();
$myRequestUri = '/checkout/cart';

$front        = $app->getFrontController();
$request      = $front->getRequest();

$request->setRequestUri($myRequestUri);

// dispatch everything
$front->dispatch();
?>

Dispatching goes OK, but i need to strip this down to just the body or a certain block. Also the generated HTML should be returned instead of outputting it directly (better not using output buffering).

Any help is welcome.

// Roland

Edit: I've added the progress i made, stil leaves me with some questions.

+1  A: 

I haven't tried this, but you could break with convention and just smash your own URL into $_SERVER['REQUEST_URI']. It's considered poor form, but I'd do that before hacking the core.

EDIT: Based on your edit, glad you're getting some response. So now the problem is that you have all the HTML being returned on a page? For some pages, it may not make sense to strip out HTML. What information are we actually trying to retrieve.

So, if you really need to strip a page, what you'll need to do is modify the layout of the page. This information is stored in layout xml files. This will entail a fair bit of modification, but the idea is to add a module that checks for command line operation (isset($_SERVER['argc']) could work), and then loads a custom handle ($this->getLayout()->getUpdate()->addHandle('my_custom_handle');) which resets all the phtml files that echo header information. This is going to be problematic to do reliably and without hacking the core files, so I'd suggest looking at creating a new page w/o the information by default.

Hope that helps, Joe

Joseph Mastey
I made some progess and edited my post.
Roland Franssen
A: 

Thanks for helping me out Joe, in the meantime i made, again, a lot of progress, but still not there yet ;-)

What i actually want to achieve is that any page of magento can be dispatched. For example a valid http post request to /customer/account/login should still log me in.

Except rendering the body of the response. I dont want the layout to be rendered by default, in stead i want to fetch a block (defined in the corresponding requested layout xml) in a programmatic manner.

Short code example, of how i see it.

<?php
// code from previous post
// - load, set request uri, dispatch

$someBlock = getABlock('breadcrumbs'); // e.g. name attribute value in the xml
echo $someBlock->toHtml();
?>

Best would be handling this in the local code pool, however im not sure it's a good idea to extend (if its at all possible) the front controller.

I didnt know about layout update handles.. a layout can update? What do they mean with that...

Roland Franssen