The examples in this paper describe the method of CI mapping (loading) data to the view layer. Share to everyone for your reference, as follows:
CI has a disgusting thing, it is necessary to put all the data into the $data array in order to map to the view layer, such as:
Currently I search out the data mode from the link table of the Database (Link table, field: id name URL):
$query = $this->db->query ("Select Id,name,url from Cg_link where 1"); $links = $query->result ();//Here's $ Links cannot be transferred directly into the view layer. Error//Wrong transmission (mapping mode)://$this->load->view (' link ', $links);//correct transmission (map mode): $data [' links '] = $ Links; $this->load->view (' link ', $data);
So as long as the data transfer must be put into the $data, if you want to query a 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 () ;//Here is a piece of data, get the way, $one->name;
More interested in CodeIgniter related content readers can view this site topic: "CodeIgniter Introductory Tutorial", "CI (codeigniter) Framework Advanced Tutorial", "PHP date and Time usage summary", "PHP object-oriented Programming introduction Tutorial", " PHP String Usage Summary, "Getting Started with Php+mysql database operations" and "PHP Common Database Operations Skills Summary"
It is hoped that this article is helpful to the PHP program design based on CodeIgniter framework.