• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Views vs. Models

#1
[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?

#2
[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;

#3
[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;

#4
[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...


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.