Welcome Guest, Not a member yet? Register   Sign In
if ($this->validation->error_string)...
#1

[eluser]EEssam[/eluser]
Hello,

I'm wondering if there's a better way to write the code below in a view:


<?php if ($this->validation->error_string): ?>
<p>The following errors occurred:</p>
&lt;?php echo $this->validation->error_string ?&gt;
&lt;?php endif ?&gt;


Thanks.
#2

[eluser]nevercraft[/eluser]
I usually do something like this:

Controller
Code:
$data['warning'] = "<p>The following errors occured:</p>\n" . $this->validation->error_string;
$this->load->view('myview', $data);

View
Code:
&lt;?=@$warning ?&gt;

The @ symbol keeps CI/PHP from generating an warning if $warning wasn't set (IE: when there aren't any errors). Its the same as your method really, it just makes the view's source a little more readable.
#3

[eluser]Derek Allard[/eluser]
Supressing errors is more computationally expensive then its worth probably. You could do something like this
Code:
$data['warning'] = ($this->validation->error_string) ? "<p>The following errors occured:</p>\n" . $this->validation->error_string : '';
$this->load->view('myview', $data);




Theme © iAndrew 2016 - Forum software by © MyBB