无法使用 cakePHP requestAction 加载完整视图

发布于 2024-12-29 08:27:55 字数 372 浏览 1 评论 0原文

我有一个问题。我正在尝试使用 cakePHP 的 requestAction 方法来加载视图文件,但它似乎不起作用。在他们的页面上我们可以读到以下内容:

您可以使用 requestAction() 来检索完全渲染的视图 在选项中传递“return”: requestAction($url, 数组('返回'));

我尝试这样做,但仍然无法获取 .ctp 视图文件的内容。我有什么遗漏的吗?

顺便说一句,我正在另一个视图中执行此操作。

谢谢。

I have a question. I'm trying to use the requestAction method of cakePHP to load a view file, but it doesn't seem to work. On their page we can read the following:

You can use requestAction() to retrieve a fully rendered view by
passing 'return' in the options: requestAction($url,
array('return'));

I tried doing that, but I still couldn't get the content of my .ctp view file. Is there anything that I'm missing?

By the way, I'm doing this inside of another view.

Thank you.

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

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

发布评论

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

评论(2

我ぃ本無心為│何有愛 2025-01-05 08:27:55

该函数不仅仅加载视图文件。它模拟 Web 浏览器访问 URL 并返回相关控制器呈现的内容。默认行为是将结果发送到输出,如果您使用返回参数,您必须记住自己打印它:

$this->requestAction("MyController/myaction/param");

相当于

echo $this->requestAction("MyController/myaction/param", array("return"));

This function doesn't just load view files. It simulates a web browser accessing the URL and returns what ever the controller in question renders. The default behaviour is sending the result to output, if you use the return parameter you have to remember to print it yourself:

$this->requestAction("MyController/myaction/param");

is equivalent to

echo $this->requestAction("MyController/myaction/param", array("return"));
欢你一世 2025-01-05 08:27:55

requestAction 调用操作,而不是关联的视图。如果你想调用关联的视图,你需要这样做:

echo $this->requestAction("Mycontroller/myaction/param", array( 'return' ) );

这会让 cake 知道渲染关联的视图文件。

requestAction calls an action, not the associated view. If you want to call the associated view you need to do it like this:

echo $this->requestAction("Mycontroller/myaction/param", array( 'return' ) );

That will let cake know to render the associated view file.

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