How do You solve MySQL parent table deletion issue??
I parent table has child table records, it throws CDbException error, it would be nice to warn user about it before an ungly error What are your options?
Right this is very simple - just does nothing But how to inform the user friendly and simple?
/// ... do smth
[edit] By the way, shouldn’t this go to Controller? Also I use multiple views where delete is called, so maybe pop up promt would be the best way to inform user?
Yeah, all methods kind of solve the problem, but I need an example of right message to inform the user about the problem - Parent table ‘PTable’ has a record in child table ‘CTable’.
In my default controler Branches are parent table, courses are Child table.
...
public function actionDelete()
{
if(Yii::app()->request->isPostRequest)
{
// we only allow deletion via POST request
$this->loadModel()->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_POST['ajax']))
$this->redirect(array('index'));
}
else
throw new CHttpException(400,Yii::t('App','Invalid request. Please do not repeat this request again.'));
}
...
After try catch I miss the CDbException but how to I properly inform user? E.g. In popup or message and discontinue redirect to index?
public function actionDelete()
{
///Integrity constraint violation SEARCH
if(Yii::app()->request->isPostRequest)
{
try{
$this->loadModel()->delete();
if(!isset($e)){
if(!isset($_POST['ajax']))
$this->redirect(array('index'));
}
} catch (Exception $e) {
echo 'how to implement pop up';
} //catch end
}
else
throw new CHttpException(400,Yii::t('App','Invalid request. Please do not repeat this request again.'));
}
How could I implement pop up here with Yii logic in the same page instead of deletion error (now opens new window with ugly message ) ?