//For testing CRUD
public function crudTest() {
// @todo: Whole function permission check
// Create a CRUD main table object
$crud = new SCrud ( 'twh_adminstractor', $this->controller, $this->action );
// Configure fields
$crud->field ( 'sort' )-> ;isAbandon = true;
$crud->field ( 'id' )->title = "number";
$adm_pwd = $crud->field ( 'adm_pwd' );
$adm_pwd->isPassword = true;
$adm_pwd->encode ( function ($v) {
return md5 ( $v );
} );
$count = $crud->field ( 'count' );
$count->inInsert = false;
$count->inUpdate = false;
$endip = $crud->field ( 'endip' );
$endip->inInsert = false;
$endip->inUpdate = false;
$status = $crud-> field ( 'status' );
$status->enum = array (
'0' => 'disabled',
'1' => 'enabled'
);
$status->title = "Status";
$status->updateType = 'radio';
$createtime = $crud->field ( 'createtime' );
$createtime->isCreated = true;
$createtime->searchType = 'DateRange';
$createtime->decode ( function ($v) {
return date ( 'Y-m-d H: i:s', intval ( $v ) );
} );
$endtime = $crud->field ( 'endtime' );
$endtime->isUpdated = true ;
$endtime->searchType = 'DateRange';
$endtime->decode ( function ($v) {
return date ( 'Y-m-d H:i:s', intval ( $v ) );
} );
// Enable banned users
$enable = $crud->operationRow ( 'Enable' );
$enable->title = "Enable";
$enable->filter = function ($row) {
return $row ['status'] == 0 and $row ['id'] != 1;
} ;
$enable->do = array($this,'doEnable');
// Disable enabled users
$disable = $crud->operationRow ( 'Disable' );
$disable->title = "Disable";
$disable->filter = function ($row) {
return $row ['status'] == 1 and $row [ 'id'] != 1;
};
$disable->do=array($this,'doDisable');
// Permission settings
$auth = $ crud->operationRow ( 'setAuth' );
$auth->title = "Permission Management";
$auth->filter = function ($row) {
return $row [' status'] == 1 and $row ['id'] != 1;
};
$auth->do=array($this,'doSetAuth');
$tOperation=$crud->operationTable('TOperation');
$tOperation->title="Table-level operation";
$tOperation->do=array($this,'tOperation ');
$mOperation=$crud->operationMulti('MOperation');
$mOperation->title="Multiple selection operation";
$mOperation->confirm= false;
$mOperation->do=array($this,'mOperation');
$crud->process ( $this->request );
}
public function mOperation(){
echo 'Test universal multi-select operation';
dump($this->request->ids);
return array('msg'=> 'Performed a general multi-select operation');
}
public function tOperation(){
echo 'Tested a general table-level operation';
return array('msg'=> ;'Performed a common table-level operation','go'=>'list');
}
public function doEnable(){
echo 'Enable a user';
return array('msg'=>'A user is enabled','go'=>'list');
}
public function doDisable(){
echo 'Disable A user';
return array('msg'=>'Disabled a user','go'=>'list');
}
public function doSetAuth(){
echo 'Set permissions';
return array('msg'=>'Set permissions, will jump to another address','go'=>LUrl::ice().'/?c =maintain&a=setAuth');
}
The above code cannot run independently and requires the entire Framework support, but developers can extract corresponding functions
The above is the general CRUD function framework (3) in the fast backend in the IcePHP framework. The content of specific business examples. For more related content, please pay attention to PHP Chinese website (www.php.cn)!
The above is the content of the specific business examples of the general CRUD function framework (3) in the fast backend in the IcePHP framework. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!