我正在尝试弄清楚如何在控制器内使用我的视图元素之一...
I'm trying to figure out how to use one of my view elements inside of a controller...
我知道,我知道:不要那样做!"(99% 的情况下这是正确答案)
I know, I know: "Don't do that!" (99% of the time this is the correct answer)
但我认为我确实有充分的理由.该操作正在处理返回标记的 AJAX 请求.返回的标记是一个列表,我使用元素在其他地方显示它.所以为了保持我的代码干燥,我认为在这里这样做是合适的.
But I think I actually have a good reason. The action is handling an AJAX request which returns markup. The returned markup is a list which I display everywhere else using an element. So in an effort to keep my code DRY, I think it's appropriate to do this here.
这可能吗?
简单:
$view = new View($this, false);
$content = $view->element('my-element', $params);
还有:
不要再这样做了!!!
这篇关于CakePHP:如何在控制器内使用视图元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
不能使用 'Object 作为类名,因为它是保留的Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作为类名,因为它是保留的 Cake 2.2.x)
OAuth 重定向后会话丢失Session is lost after an OAuth redirect(OAuth 重定向后会话丢失)
Cakephp 3.x 中的分页排序Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分页排序)
CakePHP 多个应用程序的共享核心CakePHP Shared core for multiple apps(CakePHP 多个应用程序的共享核心)
在 CakePHP 3 上登录 [ Auth->identify() ] 始终为 falLogin [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登录 [ Auth-identify() ] 始终为 false)
致命错误:允许的内存大小为 134217728 字节已用尽Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命错误:允许的内存大小为 134217728 字节已用尽