Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将数据传递到模板并返回渲染结果_Php_Codeigniter_Codeigniter 3 - Fatal编程技术网

Php 将数据传递到模板并返回渲染结果

Php 将数据传递到模板并返回渲染结果,php,codeigniter,codeigniter-3,Php,Codeigniter,Codeigniter 3,我已经阅读了有关CodeIgniter的文档和搜索论坛,但没有找到可能或不可能的答案 我想知道是否有可能将值传递给视图进程并返回它的值。如果可能的话怎么办?如果没有,还有什么选择?基本上,我正在尝试使我的导航栏动态化。提前谢谢 这是我的控制器: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Faculty extends CI_Controller { public fu

我已经阅读了有关CodeIgniter的文档和搜索论坛,但没有找到可能或不可能的答案

我想知道是否有可能将值传递给视图进程并返回它的值。如果可能的话怎么办?如果没有,还有什么选择?基本上,我正在尝试使我的导航栏动态化。提前谢谢

这是我的控制器:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Faculty extends CI_Controller
{
    public function index()
    {
        $data1['navbar'] = $this->_navbar(1);
        $data['nav'] = $this->load->view('layouts/nav', $data1, TRUE);
        $this->load->view('Facultypage', $data);
    }

    function _navbar($i) {
        $activebar = array('', '', '', '', '');
        $activebar[$i] = 'active';
        return $activebar;
    }
}

视图文件中的
可以直接基于控制器设置活动类,后跟方法名

例如:
$this->uri->segment(1);//控制器
$thi->uri->段(2);//方法等

<ul class="nav navbar-nav nav-helper" id="navlist">
<li class="<?php if($this->uri->segment(1)=='' ) { echo 'active'; } ?>"><a href="index.php">Home<span class="sr-only">(current)</span></a></li>
<li class="<?php if($this->uri->segment(2)=='Faculty') { echo 'active'; } ?>" id="faculty"><a href="Faculty">Faculty</a></li>
<li class="<?php if($this->uri->segment(2)=='Enroll') { echo 'active'; } ?>" id="enroll"><a href="Enroll">Enroll</a></li>
<li class="<?php if($this->uri->segment(2)=='News') { echo 'active'; } ?>" id="news"><a href="News">News</a></li>
<li class="<?php if($this->uri->segment(2)=='About us') { echo 'active'; } ?>" id="about"><a href="About">About us</a></li>

    欢迎加入,Codeigniter simple将load view第二个参数作为数组,您可以在视图中将这些数组键用作php变量。。
    <ul class="nav navbar-nav nav-helper" id="navlist">
    <li class="<?php if($this->uri->segment(1)=='' ) { echo 'active'; } ?>"><a href="index.php">Home<span class="sr-only">(current)</span></a></li>
    <li class="<?php if($this->uri->segment(2)=='Faculty') { echo 'active'; } ?>" id="faculty"><a href="Faculty">Faculty</a></li>
    <li class="<?php if($this->uri->segment(2)=='Enroll') { echo 'active'; } ?>" id="enroll"><a href="Enroll">Enroll</a></li>
    <li class="<?php if($this->uri->segment(2)=='News') { echo 'active'; } ?>" id="news"><a href="News">News</a></li>
    <li class="<?php if($this->uri->segment(2)=='About us') { echo 'active'; } ?>" id="about"><a href="About">About us</a></li>