Codeigniter: how to handle direct link to controller / function / param?

I have a simple controller function that deletes a database record (the model function is used for this). I have a link to this in one of my views (e.g. http://www.example.com/item/delete/3 ) and Im using jQuery displays a confirmation dialog to make sure that the user really wants to delete it . Everything is fine. However, if you simply enter this URL in your browser, the item will be deleted without warning.

Is there a way to handle this either in how I code the controller function or in the model?

+3
source share
4 answers

HTTP.

function delete()
{
    if ($id = $this->input->post('id'))
    {
        $this->item_model->delete_item($id);
    }
}

JQuery HTTP-.

$.ajax({
    type: 'POST',
    url: 'item/delete',
    data: {id:item_id}
});

, URL- -.

0

, ( CI Forum).

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class SomeModel extends Model
{
// model code
}
?>

, CI .

0

, , , ..

function _delete($id) {
 ...delete code goes here...
}
0

AJAX? , POST GET, .

GET, , , , .

, 100% .

0

Source: https://habr.com/ru/post/1740034/


All Articles