Home >Backend Development >PHP Tutorial >Yii uses ajax verification to display error messagebox solution, yiimessagebox_PHP tutorial
The example in this article describes the solution to the error messagebox displayed in Yii using ajax verification. Share it with everyone for your reference. The specific method is as follows:
Yii comes with ajax form verification. Some friends may not know this, but I encountered some problems today when using the ajax form verification that comes with yii. Let me compile examples for your reference.
In Yii, you can use ajax to execute an action, but this action sometimes needs to pop up an error message. The handling method is as follows
Basic idea
Use exception, such as:
If this exception is CHttpException or YII_DEBUG is true, the error message can be displayed through CErrorHandler::errorAction. In the code generated by yiic by default, this is achieved by adding the following code to config/main.php
But in Yii 1.1.9 and above, exceptions thrown by ajax requests are displayed through CApplication::displayException(). This prevents us from customizing how messages are displayed.
This is what it looks like if the CGridView deletion request throws an exception, (YII_DEBUG is true)
Yii 1.1.9 The logic for checking ajax requests has been removed, so now even ajax exceptions are handled through CErrorHandler::errorAction.
In this way, ajax messages can be DIYed.
Example
Pass the following code
Later I found a webmaster who shared a piece of code
model:
You may use Markdown syntax.
这样好像很好的解决了yii ajax显示问题。
希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。