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



我正在使用 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

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

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

最新更新