Magento 调度外部应用程序

发布于 2024-08-23 01:28:32 字数 498 浏览 9 评论 0原文

我试图弄清楚 Magento 的调度系统到底是如何工作的。

我想从应用程序目录外部调度布局的特定部分(例如主体)。

到目前为止我所拥有的;

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

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

$request->setRequestUri($myRequestUri);

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

调度一切顺利,但我需要将其剥离为仅正文或某个块。 另外,应该返回生成的 HTML,而不是直接输出(最好不要使用输出缓冲)。

//罗兰

编辑: 我已经添加了我所取得的进展,但仍然留下了一些问题。

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).

// Roland

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初见你 2024-08-30 01:28:32

我还没有尝试过这个,但你可以打破惯例,将你自己的 URL 粉碎到 $_SERVER['REQUEST_URI'] 中。这被认为是糟糕的形式,但我会在破解核心之前这样做。

编辑:
根据您的编辑,很高兴您得到一些回复。那么现在的问题是您是否已在页面上返回所有 HTML?对于某些页面,删除 HTML 可能没有意义。我们实际上想要检索哪些信息。

因此,如果您确实需要剥离页面,您需要做的就是修改页面的布局。此信息存储在布局 xml 文件中。这将需要进行相当多的修改,但想法是添加一个检查命令行操作的模块(isset($_SERVER['argc']) 可以工作),然后加载自定义句柄($this ->getLayout()->getUpdate()->addHandle('my_custom_handle');) 重置所有回显标头信息的 phtml 文件。要可靠地做到这一点并且不破坏核心文件,这将是有问题的,因此我建议考虑创建一个默认情况下不包含信息的新页面。

希望有帮助,

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

五里雾 2024-08-30 01:28:32

谢谢你帮助我,乔,与此同时,我再次取得了很大的进步,但仍然还没有;-)

我真正想要实现的是可以调度 magento 的任何页面。例如,对 /customer/account/login 的有效 http post 请求仍应让我登录。

除了呈现响应正文之外。我不希望默认呈现布局,而是希望以编程方式获取块(在相应请求的布局 xml 中定义)。

简短的代码示例,展示我的看法。

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

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

最好是在本地代码池中处理这个问题,但是我不确定扩展(如果可能的话)前端控制器是个好主意。

我不知道布局更新句柄..布局可以更新吗?他们说这句话是什么意思...

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文