CodeIgniter call model to view?

I have a view that maps a data table, this data is generated on the model. How can I name this model in my view for publication in my view ...? What is the equivalent of what I want to do with codeIgniter in php:

while($row = mysql_fetch_array($requet))
      {
// code of displaying my data;
      }
+4
source share
5 answers

try using $CI =& get_instance()

then load your model as follows:

$CI->load->model('someModel')

then call your model function as follows:

$result = $CI->someModel->somefunction()

then display with foreach

foreach($result as $row){ $row->somecolumnName }

+14
source

I think it is not a good idea to call a model directly from a view.

,

$this->load->model('my_model');
$my_data['my_array'] = $this->my_model->get_my_data();
$this->load->view('your_view', $my_data);

:

foreach($my_array as $item){
    echo $item;
}
+2

. . , . ... foreach.

+1

.

<?php
$CI =& get_instance();
$CI->load->model('MyModel');
$result= $CI->MyModel->MyMethod($parameter)->result_array();        
  foreach($result as $row){ 
         echo $row['column_name'];                      
    }
?>
+1

. : MVC

:

function getdata() {
  $query = $this->db->query($sql);
  return $query->result_array();
}

:

foreach($this->modelname->getdata() as $item) {

}
0

All Articles