假设您使用的是标准column\\u cb()函数,列表表将以$\\u GET的形式传递数组中所选行的ID,标记为您在列表表的构造函数中指定给“singular”的任何内容。
下面是一个典型的column\\u cb():
function column_cb($item){
return sprintf(
\'<input type="checkbox" name="%1$s[]" value="%2$s" />\',
/*$1%s*/ $this->_args[\'singular\'], //Let\'s simply repurpose the table\'s singular label ("video")
/*$2%s*/ $item->id //The value of the checkbox should be the record\'s id
);
}
例如,假设我有一个显示视频的列表表。构造函数如下所示:
function __construct(){
global $status, $page;
//Set parent defaults
parent::__construct( array(
\'singular\' => \'video\', //singular name of the listed records
\'plural\' => \'videos\', //plural name of the listed records
\'ajax\' => false //does this table support ajax?
) );
}
因此,如果选中列表中的三行,从批量操作列表中选择“删除”,然后单击“应用”,则可以使用$\\u GET[\'video\']访问所选行。
function process_bulk_action() {
//Detect when a bulk action is being triggered...
if( \'delete\'===$this->current_action() ) {
foreach($_GET[\'video\'] as $video) {
//$video will be a string containing the ID of the video
//i.e. $video = "123";
//so you can process the id however you need to.
delete_this_video($video);
}
}
}