简体   繁体   English

如何在同一页面上显示一个控制器的两个视图

[英]How to show two views of one controller in the same page CAKEPHP

I have a doubt for few days ago. 我几天前有疑问。 I hope to explain well, and sorry for my english. 我希望解释得很好,对不起我的英语。

Im working with CakePHP, well, i have some controllers with their own views, etc.. What happens is: i have two functions in my controller, and i want that, when i do mouse click on one element (in this case, google chart pie chart) of my view "ONE", i want to execute the other function of the controller (that renders view "TWO") from the view ONE, BUT, in the SAME page. 我正在使用CakePHP,嗯,我有一些具有自己视图的控制器,等等。发生了什么:我的控制器中有两个函数,当我在一个元素上单击鼠标时,我想要那个(在这种情况下,谷歌我的视图“一个”的图表饼图),我想从同一页面中的视图“但”执行控制器的其他功能(该视图呈现“两个”视图)。

I know how to treat the click on pie chart, this isnt the problem. 我知道如何处理饼状图上的点击,这不是问题。 The problem IS, how to keep visible the view ONE when i treat the click on it and go to the other view TWO. 问题是,当我单击一个视图并转到另一个视图两个时,如何保持视图一可见。 So i mean, i want to have in the end, the page default with the two views, ONE and TWO, that each has her own function in controller, it isnt a simple view, like a text, table... 所以我的意思是,我想最后让页面默认具有两个视图,一个和两个,每个视图在控制器中都有自己的功能,它不是一个简单的视图,例如文本,表格...

I have tried some solutions: requestaction, href of javascript, helpers... but i dont get the solution. 我尝试了一些解决方案:requestaction,javascript的href,帮助程序...,但是我没有解决方案。

I'd be very grateful if you could help me! 如果您能帮助我,我将不胜感激! Any question ask me, and i hope to have explained well and that you understand my english! 任何问题都问我,我希望能很好地解释您,并且您理解我的英语!

Greetings! 问候!

The only way you can do it is by making element with one of your views and then add this element in the other view. 唯一的方法是使用其中一个视图创建元素,然后在另一个视图中添加此元素。 You can simply add an element in your view with $his->element('ElementName'); 您只需使用$his->element('ElementName');在视图中添加一个元素即可$his->element('ElementName'); . See http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Views.html for more information about elements in cakephp. 有关cakephp中元素的更多信息,请参见http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Views.html

Put $this->element('name'); $this->element('name'); in a div and using ajax you might be calling the function i guess. 在div中并使用ajax,您可能正在调用我猜的函数。 So in the controller function write something like this: 因此,在控制器函数中编写如下代码:

$this->set('set your variables for the elements here');
$view = new View($this, false);
$content = $view->element('my-element');
json_encode($content);

and catch this response in success part of your ajax call. 并在ajax调用的成功部分中捕获此响应。

success: function (data){
    $("#div_id").html(data);
}

I hope that makes sense. 我希望这是有道理的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM