I have a problem transferring data from Controller to View.
I use Ajax for this, you can see my Ajax code here:
$(document).ready(function(){
$('li.thang').click(function(){
var id_thang = $(this).attr('value');
$.ajax({
url: baseUrl+'/Home/getImage',
dataType: 'json',
type: 'POST',
data: {id_thang: id_thang},
}).done(function(result) {
console.log(result.get_list_image_thang);
})
});
});
I get id_thangwhen clicked in HTML tags li > thang.
In Controller / Home.phpI will get the array data on this id_thang.
function getImage(){
$id_thang = $this->input->post('id_thang');
$input = array();
$input['order'] = array('id','ASC');
$get_image_thang = $this->Mmenushoatnao->get_info($id_thang);
ob_start();
}
All data is stored in an array $get_image_thang.
Finally, I don’t know how to pass this array to the View to show all the data that I have selected.
In the /index.php view, I am trying to loop foreachthrough all the data in this array and show in the tag <html>. Like this:
<?php foreach($get_image_thang AS $item) ?>
<div class="col-md-4 col-sm-4 col-xs-4">
<?php echo $item->id; ?>
</div>
<?php endforeach ?>
Note: View / index.phpthere is a demo code.
The problem is that I do not know how to send $get_image_thangto this view.
Update 1:
console.log(result); .done(function(result) :

: row += result[i].id; id, name, image_list undefined.
2:
, id. core/MY_MODEL.php:
function get_info($id, $field = '')
{
if (!$id)
{
return FALSE;
}
$where = array();
$where[$this->key] = $id;
return $this->get_info_rule($where, $field);
}
function get_info_rule($where = array(), $field= '')
{
if($field)
{
$this->db->select($field);
}
$this->db->where($where);
$query = $this->db->get($this->table);
if ($query->num_rows())
{
return $query->row();
}
return FALSE;
}
get_info. :
Mmenushoatnao - .
3:
Controller click.
. Ajax.
:
function getImage(){
$id_thang = $this->input->post('id_thang');
$input = array();
$input['order'] = array('id','ASC');
$get_image_thang = $this->Mmenushoatnao->get_info($id_thang);
ob_start();
?>
<?php foreach($get_image_thang as $item): ?>
<?php $image_list = json_decode($item->image_list); ?>
<?php foreach($image_list as $image): ?>
<div class="col-md-4 col-sm-4 col-xs-4">
<img src="<?php echo upload_url() ?>/img/hoatnao/hinhanh/<?php echo $image ?>" alt="Image" class="img-responsive">
</div>
<?php endforeach; ?>
<?php endforeach; ?>
<?php
$return = ob_get_clean();
$data['result']=$return;
echo json_encode($data);
}
, .
, Ajax.