I have a problem with the error page 500 of symfony (apps/%app-name%/config/error/error.html.php).
I had to learn that symfony skip the standard way of page creation completely. I had to organize all the helpers myselve.
require_once dirname(__FILE__) . '/../../../../lib/vendor/symfony/lib/helper/HelperHelper.php';
use_helper('Tag', 'Asset', 'Url', 'I18N', 'Date', 'Partial');
But now I am missing the contents of the configuration. How can I manually trigger the autoloader mechanism, so that I get the information from view.yml and so on?
I don't know if it's smart to depend on the whole Symfony stack when you're displaying an error.
IMHO the error pages need to be designed as light-weight as possible, 99% static HTML, with only some php code to display a friendly error message.
Because, what if something is wrong with your Symfony stack, then you can't even present a decent error page to the user.
The 500 error page is also a "hard fail" page, it is the most generic error handler which is only shown if no action tried to catch the exception.
In the cases where you want to use the view and everything, I think it's better to catch the exceptions right there in the action, and present better error pages (return sfView::ERROR) with information the user can act on.
Related
As shown in the php documentation is it possible to create your own exception handler. I see this as a reasonable way to handle my user generated errors and exceptions throughout the project I am working on. Through research I have made a decent amount of progress in implementing a specific one, just for one class, including things like using ErrorException (from the first answer) and making sure to return false for error levels that I can't handle.
I have however run into a wall with making it more generic. I don't want to have to write a separate handler for every class I write (especially because the vast majority of that code is going to be the same for every one). Yet it feels like terribly bad practice to have every single error for the entire project in the same handler.
The closest I have gotten to what feels like an acceptable solution is to write a subclass of ErrorException for every class I want to handle the errors for and store messages in each of those. But even with this I am probably going about it wrong (I don't think that would be the proper place to store default error messages). Is there a universally accepted way of doing this that I have been unable to find? or is one of these ways actually the way it's generally done? or are there multiple solutions that are scalable based on the size of the project?
EDIT: Just realized I can write a generic Exception_Handler with the reused code and extend it for each set of errors I have (real herp moment for me), but it still seems like I should handle all errors in the same place. If I'm completely wrong, let me know.
EDIT 2: Decided to go with a config file containing the error messages for each class that will throw errors, then the name of the class that throws the error defines what config file is loaded to get the list of messages associated with error number. This also allows me to easily define messages that should get logged as opposed to messages that should get sent to the user (essentially specific vs. generic messages).
I guess I'll mark this as answered or something, but if I'm doing something wrong feel free to let me know, help is always appreciated.
Decided to go with a config file containing the error messages for each class that will throw errors, then the name of the class that throws the error defines what config file is loaded to get the list of messages associated with error number. This also allows me to easily define messages that should get logged as opposed to messages that should get sent to the user (essentially specific vs. generic messages).
More specifically I'll probably use an ini file that defines an array of arrays where each number contains the array of error messages for that error number. Then use a foreach with the thrown error numbers to return the error message(s).
I have a question regarding error handling in Zend. I am fairly new to zend frame work.
I am new on this project that i am working on and the previous developers didn't handle service errors and the application is fairly large so I am trying to figure out an easy way to handle all the errors the service returns, and even handle the errors when service fails.
so when ever there is an error we need to alert the user that something is wrong and show the error.
now since i will be getting that in Model, how do I handle this in elegant way so that there is not much rework to be done.
Can i create a common class and extend it? I also need to alert the user in case of any error.
I want a better way because I have more than 150 controller files and about more than 100 model files.
Thanks
For a ZF app that's using Zend_Application, you should ensure that your application.ini file has this in it:
resources.frontController.throwExceptions = false
Then any Exception that is thrown will be trapped and the ErrorController's errorAction() method will be called. This gives you a centralised place to handle errors.
I am trying to build a custom MVC framework in PHP. I'm just starting out with this MVC and framework stuff and I'm not very good.
I created all the general stuff. The library for the model, controller and view and I got a general app up and running.
I would like to now incorporate some error handling. Primarily on the user side for bad urls. I want to make Page Not Found or 404 Errors. So i need a way to check for bad controllers,actions and query strings. And then send the users to a 404 page.
What is the best practice for doing this in an MVC environment?
EDIT
This is a learning based project it is not for production.
First of all it is not recommended to develop a custom framework your own if you are planning it for production. There are many great frameworks that you can make use of, with good flexibility and more importantly with more performance.
Coming to the problem. First write a custom exception handler for managing 404. I recommend to call them in your system/core class where you create Object of the controller and invoke the action, if they dont exists.
Add an error handler in your bootstrap.
For example, in mine I have:
public function error(){
$this->view->msg = 'Page not found';
$this->view->render('error/index');
}
Add a check for the method in the bootstrap. Where depends on your structure. If the method or controller isn't found call the error() method.
Thats probably the simplest way.
you can use .htaccess (if using apache) to route all request to your index page. Usually the the controller (and action), view is associated with a file or function. so, if you want to show custom error message, just check for the file, class, or its methods.
for example:- index.php?controller=control1&action=action1.
if(!file_exists('control1.php'))
if(!method_exists($controller, 'action1'))
//route to error handler
Well, if you are learning like you said, you shouldn't use your framework for production code because one thing is breaking the app at home and another one is loosing money with angry clients :)
Back to the problem. I've built my own custom framework for PHP applications and I have in my framework several Routers. The idea is that each Router handles a specific pattern of Route, like this:
http://someapplication.org/services/awebservice/
This code would call the ServiceRouter, which handles Routing web services. Before calling any Router I check if the Router exists, and if it does, then I would call a method to check if the route is valid, something like this:
if ( RoutingManager::RouterExists($route) )
{
$router = RoutingManager::GetRouter($route);
if ( !$router->IsValid )
RoutingManager::RedirectTo404();
}
The idea is to locate your 404 handler to a class, and delegate the task of routing into different classes to allow a variety of Routers and make your application more changeable (scalable)
Hope I can help!
Hey guys, I'm writing a library that will reside in the /lib folder that deals with processing a credit/debit card transaction.
I'm using the Forms framework to accept and validate the card details and then from my actions.class.php for that module, it instantiates my custom library that deals with the SOAP call to process the transaction.
My question is what is the best way to handle the potential errors, ie. setting up the SOAP call, processing the call, and then handling the response, which in terms of the transaction might be success or fail (with more information to feed back?).
I'm thinking something like a global error array and pre-defined error messages set in a config file somewhere. My actions.class.php ultimately receives a TRUE or FALSE, but if FALSE I need to inspect the error array and deal with it accordingly.
Any ideas?
Thank
What is the "place" that knows all about the potential errors? From your description I think it's the SOAP library. If it's your library, you should put the error codes there. Depending on how you show the errors to the user and if/how your app is localized, you then put the actual error messages (= what the user sees) where it makes the most sense.
If the SOAP lib is not yours then inspect the documentation and see what types of errors and error messages you may receive.
I have my own AppCotroller and using the beforeRender method to make changes to $this->viewPath based on the desired output format.
Is there a way I can check if Cake is currently outputting an error message? If I change the viewPath and then it's displaying an error (like can't load model, etc) it will error on the error :)
By the time Cake is displaying the error it should already be too late to do something about it. Not quite sure why you'd get an error about missing models when you change the viewPath, I hope that was just an example.
You might have some luck overriding or extending the ErrorHandler to intercept errors, but I wouldn't recommend doing that. Errors don't exist to be hidden, they're there to tell you something.
Creating a custom View might be a good idea depending on what you want to do (see the MediaView as an example of an alternative view).
The best thing to do though should be to avoid triggering errors by only allowing certain, predefined views to be set or making sure that a certain view file exists before trying to invoke it.