Welcome Guest, Not a member yet? Register   Sign In
Problem with checking data in view (model accessing)
#1

[eluser]jacobson[/eluser]
Hello I have a problem... In my view i have the foreach loop which generates the links one under the another. Now each of this links has a button "enroll" and I have the jquery script which adds the data to database after clicking this "enroll" button. Now I want to have an If statement which will check whether the user is enrolled to the event or not. If hes not than the enroll button will be visible if he's enrolled, it'll be invisible. In order to do this I need to check the mysql database if there exist the record.

In the foreach loop there is "id" generated which is used to enroll user to event and also would be needed to make the button invisible. I know that accessing model from the view is "bad" but mabe someone has any good idea how to do this in some other way ?
Mabe I'll provide a little bit of my code ... Tongue

Code:
foreach ($records as $item) {
    ?>
        <div class="content_main_entry"><a >id; ?&gt;">
            <span class="content_main_entry_value">Time</span></a></div>
        <div class="content_main_entry_enroll">
            &lt;?php
            $is_logged_in = $this->session->userdata('is_logged_in');
            if (isset($is_logged_in) && $is_logged_in == TRUE){ ?&gt;
          &lt;!-- and here I want the if statement which will check if the button should be visible or not --&gt;
                <a href="##">id; ?&gt;')">Enroll</a>
            &lt;?php
            } else if(!isset($is_logged_in) || $is_logged_in != TRUE){
                ?&gt; <a href="##">Enroll</a> &lt;?php
            }
            ?&gt;
            
        </div>
&lt;?php  
}
?&gt;

Thx for responding Smile
#2

[eluser]ProImage Web[/eluser]
create the function that performs the check in a helper or library file, call the helper or library file in your controller. Then your function will be available to you in the view so that you can perform the check using the function.




Theme © iAndrew 2016 - Forum software by © MyBB