如何将数据从Controller传递到CodeIgniter中的View?

时间:2017-03-17 05:45:52

标签: codeigniter

如何将数据从Controller传递到CodeIgniter中的View?

控制器

<?php  
defined('BASEPATH') OR exit('No direct script access allowed');   
class Hello extends CI_Controller {       
    public function index()  
    {  
        $data['hello']= "helloooo";
        $this->load->view('hello_world');  
    }  
}

3 个答案:

答案 0 :(得分:1)

<?php  
defined('BASEPATH') OR exit('No direct script access allowed');   
class Hello extends CI_Controller {       
    public function index()  
    {  
        $data['hello']= "helloooo";
        $this->load->view('hello_world',$data);  
    }  
}
在您的视图中

echo $hello;

并访问https://www.codeigniter.com/user_guide/

答案 1 :(得分:0)

select employees.employee_name ,employers.employer_name
from employees
left join employers 
on employees.employee_id = employees.employee_id
where employers.employer_name is NULL

在视图页面hello_world

jQuery(document).ready(function($) {
  $('.test1').click(function() {
    var p = $(this);
    var position = p.position();
    console.log(position);
  });
});

答案 2 :(得分:0)

在加载视图时将数据作为参数传递。

{{1}}