views:

30

answers:

1

Hi There,

I have started a new project at work today and a fellow developer has asked me to look into changing the way I work and implementing objects into my views to I can do checks within my view using the object.

To me this seems wrong, as surely this is the work of the Model and/or controller? Or am I wrong? I assume he is wanting me to implement something like this?

<?php if($user->can()) : ?>
Hello You can do this
<? endif; ?> 

$user would be the object.

Is this possible? Is it the right way to do things? How would I do this?

+2  A: 

Yes this is possible. When you want to do this you have to assign the user var to the view, I'f my memory doesn't let me fall, you have to place this in your controller:

To load a view you just type this:

$data = array (
    'user' => $userObj
);
$this->load->view('viewname', $data);
Ronn0
This is correct, if set the object to the stream which is passed to the view you can use it as an object within the view.
evolve
@evolve: thanks, it's a long time i've used CodeIgniter. So thanks for your check! :-)
Ronn0