使用codeigniter在div标签内加载视图 [英] load view within div tag using codeigniter
问题描述
我正在为我的网站使用codeigniter.我有一种情况可以在另一个视图中加载视图.我如何做到这一点.Codeigniter遵循MVC模式,因此在没有控制器帮助的情况下我们无法直接加载另一个视图. 这是我的菜单视图页面
I am using codeigniter for my website.i had a situation to load a view within another view.how could i do this.Codeigniter follows the MVC pattern so we cannot directly load the another view without the help of controller. here is my menuview page
<table align="center" width="200" border="0" style="margin-left:160px">
<tr align="left">
<td ><input type="radio" id="R1" name="R1" value="1" />PieChart</td>
<td><input type="radio" id="R1" name="R1" value="2" />BarChart</td></tr></table>
<div class="clear"></div>
<div id="chart_div"></div>
其中id为"chart_div"的div此处我要加载另一个名为chart.php的视图属于view.当用户选择单选按钮时,如何加载chart.php视图页面.
where the div with id "chart_div" here i want to load another view called chart.php belongs to view.how could i load the chart.php view page when user select radio button.
推荐答案
CI允许您将视图作为变量返回.这不是很常见,但是您可以在 docs 的最底部找到信息.基本上,您将需要执行以下操作:
CI lets you return a view as a variable. It is not very common, but you can find information at the very bottom of the docs. You're basically going to need to do something like this:
$charDiv = $this->load->view( 'chart', $charDivVars, TRUE );
$this->load->view( 'menuview', array( 'chart_div' => $chartDiv ) );
然后,在您看来:
<div id="chart_div"><?php echo $chart_div; ?></div>
这篇关于使用codeigniter在div标签内加载视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!