Welcome Guest, Not a member yet? Register   Sign In
Using $this in views.
#1

[eluser]Sayian[/eluser]
Hi,

Is there anything wrong with doing the following in views?

Code:
<? if(isset($error_msg)) { ?> // assigned from controller if login error

    <div class="error"><strong>The following errors have occured:</strong><br />&lt;? echo $error_msg; ?&gt;</div>

    &lt;? } elseif(validation_errors()) { ?&gt; // login details didnt pass validation

    <div class="error"><strong>The following errors have occured:</strong><br />&lt;? echo validation_errors(); ?&gt;</div>

    &lt;? } elseif($this->session->flashdata('status')) { ?&gt; // sent from signup page to show account was created and they can login now.

    <div class="success">&lt;? echo $this->session->flashdata('status'); ?&gt;</div>

    &lt;? }else{ ?&gt;

    <div class="announce">Please Login or <a href="/signup" title="Create account">Signup</a> to continue.</div> // default message

    &lt;? } ?&gt;

In particular I'm referring to using $this->session->flashdata in the view.

Thanks.
#2

[eluser]Isern Palaus[/eluser]
Hello Sayian,

There is nothing wrong because it works, the other things is if ethic with the basic Model-View-Controller which pretends to "separate" the logic from consults and showing... which I can't say I've no idea at all. It's not recommended to code logic on the view, but this will return you a string (or similar).

It wouldn't generate a error.

Regards,
Isern
#3

[eluser]K-Fella[/eluser]
It's perfectly acceptable to use it in views.




Theme © iAndrew 2016 - Forum software by © MyBB