Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method Illuminate\\View\\View::__toString() must not throw an exception in unix

Tags:

php

laravel-4

I am using laravel 4.2

die(View::make('amendments.changesPopUp', $this->data));

This is the code that I am using to get the view for an ajax call. This is working for my local machine running on windows but this is not working for server( unix ). Any idea as to why this is hapening?

and yes the I have checked the lowercase and upper case, the cases for the filename matches. and the weird thing is the error points to the line 0 of the controller that it is using.

This is the error that I get

{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Method Illuminate\\View\\View::__toString() must not throw an exception","file":"mysite.com/app/controllers/myController.php","line":0}}

Update: This worked when I used simple php file instead of a blade template. I still do not know what caused the error?

like image 848
developernaren Avatar asked Sep 24 '14 04:09

developernaren


2 Answers

As mentioned already, don't use die() for other than debugging purposes.

Another thing to note is that because PHP's error handling for __toString implementations is really bad (no stack traces etc), use echo View::make(...)->render() instead of just echo View::make(...) to get more descriptive errors - though in your case you can replace echo with die.

But again, don't use die.

like image 71
Andreas Avatar answered Oct 04 '22 15:10

Andreas


You should never die() out an input. Laravel expects to handle the response, and you are short circuiting the framework by using die().

Your response should simply be

return View::make('amendments.changesPopUp', $this->data);

That will then only print the changesPopUp file - which will be correctly interrepted by the browser for the AJAX call.

like image 30
Laurence Avatar answered Oct 04 '22 16:10

Laurence