Welcome Guest, Not a member yet? Register   Sign In
$this->validation->error_string; doesn't work in controller
#1

[eluser]KeyStroke[/eluser]
I'm trying to fetch the error string within my controller by using:
Code:
$this->validation->error_string;
but it returns an empty string when validation fails. It works fine when I place it in my View, but not in the controller.

How do I make it work?
#2

[eluser]Ahmed Nuaman[/eluser]
Check that you have included this:

$this->load->library("validation");
#3

[eluser]KeyStroke[/eluser]
I have. Otherwise it wouldn't have worked in the View. Smile
#4

[eluser]Ahmed Nuaman[/eluser]
Lol ok, hmmm, so you've run the validation: $this->validation->run() and set $this->validation->error_string to appear if the run() fails yeah? What are you doing with the error_string? Are you feeding it into another var?
#5

[eluser]KeyStroke[/eluser]
Yes, it only runs when validation fails.

I'm just echoing its value. I'm basically displaying a form's error messages in real-time using AJAX.
#6

[eluser]Ahmed Nuaman[/eluser]
Are you using $this->output->set_output()?
#7

[eluser]KeyStroke[/eluser]
Thanks! that worked.

What's the difference though between "echo" and "$this->output->set_output()"?
#8

[eluser]Ahmed Nuaman[/eluser]
Right:

If you've got 'compress output' on, all the content is gzipped and sent to the browser. This means your web site loads faster. What it means is that nothing can be sent to the browser until the script has been executed, so you can't use echos or prints. To find out more, read here: http://ellislab.com/codeigniter/user-gui...utput.html and http://ellislab.com/codeigniter/user-gui...tml#output




Theme © iAndrew 2016 - Forum software by © MyBB