CodeIgniter Forums
Views vs. Models - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Views vs. Models (/showthread.php?tid=11072)



Views vs. Models - El Forum - 08-25-2008

[eluser]Iverson[/eluser]
I have a function that checks to see if the visitor is logged in. Of course it returns true or false. Now I know that the logic goes into the models and controllers, but it sucks when you have to "echo" tables, divs, spans, etc. I don't want to add too much logic to my view files, but I would much rather be able to see the rendered tables. So what I decided to do was to add the "if logged in" function to the view file and throw the specific HTML in there instead of just a barebone HTML template and send the specific HTML from the model. Opinions? Or am I just missing something?


Views vs. Models - El Forum - 08-28-2008

[eluser]Crafter[/eluser]
It look like the issues is merely one of reducing the complexity of the view files. Am I on the right path here?

You can't avoid the complexity, you'll have to reduce it to an appropraite level of readability.

For example you could call a view from another view:

Code:
<?  if ($logged_in) {
<h1> Some html text </h1>
   &lt;? $this->load->views("logged_in_user_message"):
   <h1> Some html text </h1>
&lt;?  }  else  { ?&gt;
   <h1> Some html text </h1>
   &lt;? $this->load->views("not_logged_in_user_message"):
<h1> Some html text </h1>
&lt;? } ?&gt;



Views vs. Models - El Forum - 08-28-2008

[eluser]xwero[/eluser]
Personally don't like the use of objects in the views. Crafters example in my hands would be
Code:
//controller
$data['content'] = ($logged_in)?$this->load->view("logged_in_user_message"):$this->load->view("not_logged_in_user_message");
// view
<h1> Some html text </h1>
&lt;?php echo $content ?&gt;



Views vs. Models - El Forum - 08-28-2008

[eluser]Iverson[/eluser]
[quote author="xwero" date="1219930630"]Personally don't like the use of objects in the views. Crafters example in my hands would be
Code:
//controller
$data['content'] = ($logged_in)?$this->load->view("logged_in_user_message"):$this->load->view("not_logged_in_user_message");
// view
<h1> Some html text </h1>
&lt;?php echo $content ?&gt;
[/quote]

This is pretty much the route I'm going now. However, I can assume from your suggestion that you have more views than models and controllers? I guess I always thought of views in more of a general template versus using them for different instances. Maybe I'll look into that...