This article mainly introduces how to map (load) data to the view layer by CI, and analyzes the principles and correct usage of CI ing to load data to the view layer by using examples, for more information about how to map (load) data to the view layer, see the example in this article. We will share this with you for your reference. The details are as follows:
CI has a disgusting thing, that is, it needs to put all the data into the $ data array to map to the view layer, such:
Currently, the link Table (link Table, field: id name url) in the database is searched for as follows:
$ Query = $ this-> db-> query ("select id, name, url from cg_link where 1"); $ links = $ query-> result (); // $ links cannot be directly transmitted to the view layer. comparison of errors // transmission of errors (ing mode): // $ this-> load-> view ('link', $ links); // correct transmission (ing mode): $ data ['link'] = $ links; $ this-> load-> view ('link', $ data );
Therefore, as long as the data is transmitted, it must be put into $ data. to query a data or 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, obtaining method, $ one-> name;