I was told that if I write a return in the controller, it will loop and cause an error on Codeigniter.
For example, is it inappropriate to write(return view) as follows in Controller?
public function example {
// ...
if (some conditions ...) {
return $this->twig->display('templates/error.html');
}
return $this->twig->display('templates/success.html');
}
I'm not familiar with Codeigniter.
I considered the return value to be a problem in Controller and corrected it as follows.
public function example {
// ...
if (some conditions ...) {
$this->twig->display('templates/error.html');
return;
}
$this->twig->display('templates/success.html');
return;
}
The older version of Codeigniter may also be affecting...
(Codeigniter 2.1.3 and PHP 5.3.3 and Twig 1.36.* )
Those who mention the location of the error are not sure about it.
Errors rarely occur(ERR_EMPTY_RESPONSE).
What I want to check is if there is no problem with the above-mentioned writing method in Controller.
I assume by inappropriate you mean "will it cause errors" and the answer is no. The error those users are experiencing is usually due to connection issues on their end, or a server issue unrelated to php.
CodeIgniter in their docs even uses controller methods with return statements as a means for form validation callbacks, so it isn't unheard of.
That being said, I'm not entirely sure why you even need these return statements. exit()
would be more appropriate if you wanted to the script to stop.