We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

No error messages?

First post here :) I'm coming over from a Laravel background and am having a hard time with displaying error messages in views. I often just get a blank screen. In my public/index.php file I have this:

  try {
    //
  } catch (\Exception $e) {
      echo $e->getMessage() . '<br>';
      echo '<pre>' . $e->getTraceAsString() . '</pre>';
  }

In my php.ini file, display_errors is on.

What else do I need to do to get error messages to display in views?

edited Mar '17

Hi and welcome!

I'm not sure the block in index.php is intended catch view errors, but you can remove it anyway for tests. You can see blank page due many reasons. First I would check if the view was loaded. You can try add static content to the top of your view so you could see if it was actually loaded. If you have view hierarchy make sure you have $this -> getContent() ({{content()}} in volt). Just two random guesses.

Thanks for the welcome JaySJay! All my views have {{ content() }} at the top. Often the views aren't loading because of some kind of error in the controller/services. In this situation, how do I get Phalcon to dump the error message and stack trace?

edited Mar '17

Well, usually all php errors are dumped right after the occurence, wherever they occured, unless you don't have some custom error processing (e.g. php try/catch blocks, phalcon's beforeException event handling) and given that error reporting is setup correctly on php level. First I suggest you to check (if you haven't done yet) if php errors are dumped to the browser in plain php script(without phalcon).

PS. I use xdebug on all my test servers.



85.5k

seems like you dont have a main layout in your app ? ( maybe ) I would do a wild guess and say probably your services are not configured correctly.

try adding this in public/index.php ( after u say $di = new \Phalcon\Di... )

$debug = new \Phalcon\Debug();
$debug->listen();

https://docs.phalcon.io/en/3.0.2/reference/debug.html

if you are using ( or not ) you can check this sample app here, for "design patterns" and how services are defined there

https://github.com/phalcon/vokuro



5.3k
Accepted
answer

Thanks guys. Turns out I didn't restart apache after changing the display_errors php.ini setting. It's always the simple, stupid things...