如何将数组变量(刀片模板)传递给CodeIgniter视图?

时间:2018-04-06 10:15:14

标签: php codeigniter templates blade

我正在使用https://github.com/cntaoyu/CI-Blade框架,我的控制器是:

class Welcome extends CI_Controller
{
    public function index()
    {
        $data['student'] = array('rollno' => '1','name' => 'Joyy');
        $this->blade->view('welcome_message', $data['student']);
    }
}

查看文件

{{$name}} // this prints Joyy

@foreach($student as $users) //student or data, both dont work
    <h2>{{ $users }}</h2>                                                                
@endforeach

1 个答案:

答案 0 :(得分:0)

您可以在控制器中传递变量,并在视图文件中使用变量的受理人名称。 请考虑以下示例

class Welcome extends CI_Controller
    {
        public function index()
        {
            $data['student'] = array('rollno' => '1','name' => 'Joyy');
            $this->blade->view('welcome_message', ['students' => $data['student']]);
        }
    }

查看文件

{{$name}} // this prints Joyy

@foreach($students as $student) //student or data, both dont work
    <h2>{{ $student }}</h2>                                                                
@endforeach
相关问题