I’m trying to create a button to delete a task from a tasklist.
So far I have a page that lists all the tasks with a "Delete" button next to each task with the following code:
[indent]echo CHtml::link(‘X’, Yii::app()->createUrl(“builder/deleteTask”, array(“taskid”=>$task->id)));[/indent]
Then I have a deletTask action in my controller which then loads the correct model and deletes it based on the ID passed in. Then I have:
[indent]$this->redirect(array(‘updateTaskList/$tasklistID’));[/indent]
which returns you back to the original page with all the tasks.Is there an easier way to keep the user on the same page without the redirect?
When I leave in Yii’s default code of:
[indent]if(!isset($_GET[‘ajax’]))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));[/indent]
It sends me to the admin panel which is not what I want. Why is the redirect to the “returnURL” not working? In all my previous utilizations of this default code it’s worked fine, but those all involved using the delete button from CGridview. I don’t understand why this case is different?
jonathan1028:
I’m trying to create a button to delete a task from a tasklist.
So far I have a page that lists all the tasks with a "Delete" button next to each task with the following code:
[indent]echo CHtml::link(‘X’, Yii::app()->createUrl(“builder/deleteTask”, array(“taskid”=>$task->id)));[/indent]
Then I have a deletTask action in my controller which then loads the correct model and deletes it based on the ID passed in. Then I have:
[indent]$this->redirect(array(‘updateTaskList/$tasklistID’));[/indent]
which returns you back to the original page with all the tasks.Is there an easier way to keep the user on the same page without the redirect?
When I leave in Yii’s default code of:
[indent]if(!isset($_GET[‘ajax’]))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));[/indent]
It sends me to the admin panel which is not what I want. Why is the redirect to the “returnURL” not working? In all my previous utilizations of this default code it’s worked fine, but those all involved using the delete button from CGridview. I don’t understand why this case is different?
Sorry if I got it wrong, but it seems like your goal is to keep the user in the same page while deleting, right? Have you tried using ajaxButton?
regards