codeigniter:加载多个视图 [英] codeigniter: loading multiple views

查看:136
本文介绍了codeigniter:加载多个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想分配一个变量$ layout_data ['navigation'] = $ this-> load('layout / navigation')
导航只是一个列表。

i want to assign a variable $layout_data['navigation']=$this->load('layout/navigation') navigation is just a list. when i pass this variable to my layout the list comes at the top.

这里是我的代码:

htaccess

RewriteEngine On
RewriteBase /ci/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /ci/index.php/$1 [L]

控制器主页

<?php
    class Home extends CI_Controller{
        function index() {

            $layout_data['navigation']=$this->load->view('navigation');
            $this->load->view('layout/main',$layout_data);
        }//end of index
    }//end of class
    ?>

布局/导航(其视图)

  <li><a href="#"><span>About Us</span></a></li>
    <li><a href="#"><span>Objective</span></a></li>

layout / main(这是我的布局)

layout/main (this is my layout)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Rainbow Handicraft-giving training and employment oppurtunities to women |in association with Rainbow Children Home</title>
<link href="<?php echo $this->config->base_url('assets/css/css/style.css'); ?>" type="text/css" rel="stylesheet" media="all"/>
</head>

<body>
<div id="top_header">
    In association with Rainbow Children Home Nepals
</div>
<!-- end of top header-->
<div id="container">

        <div id="header">

                <div id="left_logo">
                </div>

                 <div id="logo">
                            <h1>Rainbow Handicraft Nepal</h1>   
                             <h2>Lakeside Pokhara 06 Nepal</h2>
                            <h3>Email- rhn@gmail.com</h3>
                 </div>


                <div id="right_logo">
                </div>

                <div id="right_logo2">
                </div>

                <div id="right_logo3">
                </div>
        </div>   

<!--end of header-->

        <div id="wrapper">

                <div id="menu">



   <div id="tabs">

<ul>
    <li></li>
<?php  echo $content_navigation;?>

      </ul>
      </div>







                </div><!--end of menu-->

                <div id="main_content">
                <div id="leftbar">
                        <div id="left_content">

                        <p class="title">mytitle</p>
 <p class="mycontent">                       

mycontent
</p>
</div><!--end of left content-->
<div id="left_content">

<p class="title">asdfasdf</p>
 <p class="mycontent">                       
sadfsadfasdf</p>
                        </div><!--end of left content-->
                        </div><!--end of left bar-->
                    <div id="rightbar">
                    <div id="right_content">
                    <div>
                      <p class="title">This is the title</p>
                   <p class="mycontent"> mycontent
                   </p>
                    </div>

                    </div><!--end of right content-->





                    <div id="right_content">
                    <div>
                      <p class="title">This is the title</p>
                   <p class="mycontent"> this is right content
                   </p>
                    </div>

                    </div><!--end of right content-->

                    </div><!--end of right bar-->






        </div><!--end of wrapper-->


     <div class="push"></div>
 </div><!--end of container-->
         <div id="footer">

                <div id="footer_main">
               Rainbow Handicraft Nepal</br>
              Po Box 210,Dihikopatan, Lakeside ,Pokhara-6,Nepal</br>
               © Copyrights 2010 All rights Reserved. </br>Designed by: <span class="sagaritabd"><i><b>sagaritabd</b></i></span>
                </div>
         </div><!--end of footer-->


</body>
</html>


when i see source of output file i see the problem but cant fix it

 <li><a href="#"><span>About Us</span></a></li>

    <li><a href="#"><span>Objective</span></a></li>

    <li><a href="#"><span>Items</span></a></li>

    <li><a href="#"><span>Contact</span></a></li><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Rainbow Handicraft-giving training and employment oppurtunities to women |in association with Rainbow Children Home</title>

<link href="http://localhost/ci/assets/css/css/style.css" type="text/css" rel="stylesheet" media="all"/>

</head>



<body>

<div id="top_header">

    In association with Rainbow Children Home Nepals

</div>

<!-- end of top header-->

<div id="container">



        <div id="header">



                <div id="left_logo">

                </div>


......

please help


推荐答案

此行:

$layout_data['navigation'] = $this->load->view('layout/navigation');

...将立即输出视图。您需要将第三个参数设置为 TRUE

...will output the view immediately. You need to set the third parameter to TRUE:

$layout_data['navigation'] = $this->load->view('layout/navigation', NULL, TRUE);

第二个参数是你的数据数组,如果你需要它。您可以传入一个空字符串或 NULL (如果您不需要它)。

The second parameter is your data array, should you need it. You can pass in an empty string or NULL if you don't need it.

指南,一路向下到底部:

It's here in the user guide, all the way down at the bottom:

  • http://codeigniter.com/user_guide/general/views.html

将数据视图作为数据返回



有一个第三个可选参数允许你改变
函数的行为,作为字符串,而不是发送
它到您的浏览器。如果要以某种方式处理数据
,这可能很有用。如果将参数设置为true(boolean),它将返回
数据。默认行为为false,将其发送到浏览器。
如果您想要返回数据,请记住将其分配给变量:

Returning views as data

There is a third optional parameter lets you change the behavior of the function so that it returns data as a string rather than sending it to your browser. This can be useful if you want to process the data in some way. If you set the parameter to true (boolean) it will return data. The default behavior is false, which sends it to your browser. Remember to assign it to a variable if you want the data returned:

这篇关于codeigniter:加载多个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆