Welcome Guest, Not a member yet? Register   Sign In
Best practise?
#1

[eluser]jeremy95[/eluser]
I have the following view file:
Code:
$this->table->set_heading('Date', 'Start', 'Stop', 'Break', 'Total', ' ');
foreach ($workdays->result() as $workday) :
    $total = $workday->stop - $workday->start - $workday->break;
    $this->table->add_row(
        $workday->date,
        $workday->start,
        $workday->stop,
        $workday->break,
        $total,
        anchor("workdays/form/$workday->workday_id", 'Edit'),
        anchor("workdays/delete/$workday->workday_id", 'Remove')
    );
endforeach;
echo $this->table->generate();
?>

As you see, there is a very simple calculation for the total of hours on a workday. But say I would have a lot more calculations, isn't it then a better practise to do those in de controller file?

And if so, how should I do that? Should I generate the table in the controller and only
Code:
echo $this->table->generate();
in the view file? Or should I loop throught the recordset twice, like once in the controller to do the math, and then again in de view to generate the table?

Thanks in advance,
Jeremy
#2

[eluser]sooner[/eluser]
if i am not wrong, you may do like this

put all your code in controller and instead of echo u can save it to an array
$data['somename'] = $this->table->generate();

and pass this $data when loading the view.
$this->load->view('viewname',$data);

In the view echo $somename; to echo the table.

hope it works
#3

[eluser]jeremy95[/eluser]
That indeed sounds correct, thank you.




Theme © iAndrew 2016 - Forum software by © MyBB