Codeigniter objects in views
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?
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);
精彩评论