Welcome Guest, Not a member yet? Register   Sign In
How can I avoid using foreach in a view?
#2

[eluser]Cristian Gilè[/eluser]
Helpers are available in the view so you can do:

Code:
<?php foreach ($received as $row): ?>
<span>&lt;?php echo $row['id']; ?&gt;</span><span>&lt;?php echo character_limiter($row['description'],60); ?&gt;</span><span>&lt;?php echo nice_time($row['time']); ?&gt;</span>
&lt;?php endforeach; ?&gt;

If you don't want the foreach statements in the view you can build the html block in the controller, save it in a variable and pass it in the view:

Code:
$data = array();
$data['html_block'] = '';

foreach ($received as $row)
{
   $data['html_block'] .= '<span>'.$row['task_id'].'</span><span>'.character_limiter($row['description'], 60).'</span><span>'.nice_time($row['time']).'</span><br/>';
);
}

$this->load->view('view_name',$data);

In your view:

Code:
echo $html_block;


I prefer to use foreach in the view.


Cristian Gilè


Messages In This Thread
How can I avoid using foreach in a view? - by El Forum - 01-27-2011, 09:20 AM
How can I avoid using foreach in a view? - by El Forum - 01-27-2011, 11:57 AM



Theme © iAndrew 2016 - Forum software by © MyBB