Welcome Guest, Not a member yet? Register   Sign In
Modifing dynamic data to views inside controller
#1

[eluser]OneCorea[/eluser]
Hi, This is a first after hardwork process, 'cause I can't receive activation email of some account.
Anyway....... Smile

I'd like to modify the result dataset object field before sending them to views..

<Model>
Code:
function getList(, ,){
   $sql = "..."
   $query = $this->db->query($sql);
   if($query->num_rows() > 0){
    return $query->result();
   }
   else { return false; }
}

<Views>
Code:
foreach($list_obj as $obj){
   echo $obj->subject;
   echo $obj->name;
...
}

<Controller>
Code:
$data['list_obj'] = $this->board_model->getList($code, $from_list, $offset);
====>" From Here, object field modification section....."
==>$data['list_obj']->subject = "Re:".subject.".....";// <--- of course it isn't worked, just for example..
$this->load->views('bList', $data);
==========================
Consequently, I'd like to modify the $query->result() object dataset field before they are sent to the views..
Is there a solution to solve my problem in CI?..

From Real Inovice CI!!!!
#2

[eluser]sophistry[/eluser]
use $query->result_array() instead of just result(). arrays are easier to manipulate.
#3

[eluser]OneCorea[/eluser]
I think, it's the only difference between result() result_array(), which is object or array...

How to modify the looping object field/array value before I send to view data..
#4

[eluser]sophistry[/eluser]
assuming you only return one record from your sql query:

Code:
// changed list_obj to list_array to show type
$data['list_array'][0]['subject'] = "Re:".subject.".....";
#5

[eluser]OneCorea[/eluser]
sophistry...!!!Thank you so much,,you're right..somecase array is far better than object to use...




Theme © iAndrew 2016 - Forum software by © MyBB