Welcome Guest, Not a member yet? Register   Sign In
Accessing models from helpers
#7

[eluser]Zack Kitzmiller[/eluser]
It's more of a best practice thing vs. a performance thing.

I usually call helpers in a few to format things I get from a database. So.

Example:

Controller
Code:
function all_users() {
    ...
    $data['users'] = $this->model->get_all_users();
    ...
}

View
Code:
<? if (!empty($users) : ?>
<ul>
    &lt;? foreach($users as $user): ?&gt;
        <li>&lt;?= full_name($user); ?&gt;</li>
    &lt;? endforeach; ?&gt;
</ul>
&lt;? endif; ?&gt;

Helper
Code:
function full_name($user) {
  return $user['firstname'] . ' ' . $user['lastname'];
}


Messages In This Thread
Accessing models from helpers - by El Forum - 05-15-2010, 09:31 AM
Accessing models from helpers - by El Forum - 05-15-2010, 09:38 AM
Accessing models from helpers - by El Forum - 05-15-2010, 09:50 AM
Accessing models from helpers - by El Forum - 05-15-2010, 09:56 AM
Accessing models from helpers - by El Forum - 05-15-2010, 09:58 AM
Accessing models from helpers - by El Forum - 05-15-2010, 10:43 AM
Accessing models from helpers - by El Forum - 05-15-2010, 10:59 AM
Accessing models from helpers - by El Forum - 03-12-2012, 04:02 AM
Accessing models from helpers - by El Forum - 03-12-2012, 07:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB