Welcome Guest, Not a member yet? Register   Sign In
passing data to a view...
#1

[eluser]Unknown[/eluser]
I've read the user manual about passing data to a view, and understand about passing arrays, but have a question about just sending a single variable. I admit that I'm just learning CI, so this may be pretty elementary...

In my controller I have

Code:
$login_error['error'] = ('<p class="error"> This login is incorrect </p>');
            $this->load->view('login_form', $login_error);
            return;

And in my view
Code:
<p class="heading">User Login</p>

    &lt;?php echo ($error); ?&gt;

This works and all.. but just to wrap my head around it, what if I just wanted to send $error as in:

Code:
$error = ('<p class="error"> This login is incorrect </p>');
            $this->load->view('login_form', $error);
            return;

How would I reference that in my view? I've tried just $error, but it gives me an undefined variable error. Is data passed to the view always an array? I think thats what the user guide is trying to say, but I wanted to be sure.

Thanks...
#2

[eluser]Georgi Budinov[/eluser]
Well the view function expects an array, then CI is merging this array with another array of cached variables and I don't think that if you send a string it will work. View function needs an assoc array in order to work otherwise it is ignored.
#3

[eluser]Unknown[/eluser]
Makes sense.. was just wondering. Thanks for the reply.




Theme © iAndrew 2016 - Forum software by © MyBB