Welcome Guest, Not a member yet? Register   Sign In
Delete function
#1

[eluser]xtremer360[/eluser]
I have a module that lists all of the content pages from my database in a HTML table. This HTML table uses the datatables jQuery plugin functionality to modify the table. In each row of the table there is a delete image that represents when clicked the user is wanting to delete that item from the database and remove the row from the HTML table.

There are two different possibilities for the user to delete this item. One is when the user clicks the link if he/she has javascript enabled then it uses a jQuery ajax call to make to a PHP delete function and return a json array, or the user can click the icon and if they don't have javascript enabled then the icon is used as a link to go to the delete function and delete the item and then redirect back to the content pages list.

What I'm wanting to know and have discussed is the advantages/disadvantages to using one or more functions in the controller for a regular php delete function and one for a jQuery ajax delete function.

This is what I have for my current code? With my desired effect do I need to come up with a different function? I've seen $this->input->is_ajax_request() but not sure if I need to use this here or not.

Code:
/**
     * Content_pages::delete()
     *
     * Deletes a content page from the list of content pages.
     *
     * @param string $content_page_id The id of the content page being deleted.
     * @return void
     */
    public function delete($content_page_id = 0)
    {
        $status = 'unprocessed';
        $title = 'Action Unprocessed';
        $message = 'The last action was rendered unprocessed. Please try again.';
        if (isset($content_page_id) && is_numeric($content_page_id))
        {
            $content_page_data = $this->content_page->get($content_page_id);
            if (!empty($content_page_data))
            {
                $this->content_page->delete($content_page_id);
                if ($this->db->affected_rows() > 0)
                {
                    $status = 'success';
                    $message = 'The content page has been successfully deleted.';
                    $title = 'Content Page Deleted';  
                }
                else
                {
                    $status = 'error';
                    $message = 'The content page was not deleted successfully.';
                    $title = 'Content Page Not Deleted';  
                }
            }
        }
        $output = array('status' => $status, 'message' => $message, 'title' => $title);
        echo json_encode($output);
    }
#2

[eluser]xtremer360[/eluser]
Any thoughts on the matter?




Theme © iAndrew 2016 - Forum software by © MyBB