Home > Article > Backend Development > Method of CI mapping (loading) data to the view layer, ciview_PHP tutorial
The example in this article describes the method of CI mapping (loading) data to the view layer. Share it with everyone for your reference, the details are as follows:
There is a disgusting thing about CI, that is, all data needs to be put into the $data array before it can be mapped to the view layer, such as:
The data method I currently search from the link table (friendly link table, field: id name url) of the database:
$query = $this->db->query("select id,name,url from cg_link where 1"); $links = $query->result(); //这里的$links是不能直接传输入view层的.对错比较 //错误的传输(映射方式): //$this->load->view('link',$links); //正确的传输(映射方式): $data['links'] = $links; $this->load->view('link',$data);
So any data transmission must be placed in $data. If you want to query a piece of data or a one-dimensional array, use the following function
$sql = "select id,name,url from cg_link where id=21 limit 1"; $query = $this->db->query($sql); $one = $query->row();//这里是一条数据,获取方式,$one->name;
Readers who are interested in more CodeIgniter related content can check out the special topics of this site: "codeigniter introductory tutorial", "CI (CodeIgniter) framework advanced tutorial", "php date and time usage summary", "php object-oriented program" Design introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" and "php common database operation skills summary"
I hope this article will be helpful to everyone’s PHP program design based on the CodeIgniter framework.