//用於測試CRUD
public function crudTest() {
// @todo:整個功能權限檢查
// 建立一個CRUD主表物件
$crud = new SCrud ( 'twh_adminstractor', $this-this>controller , $this->action );
// 對字段進行配置
$crud->field ( 'sort' )->isAbandon = true;
$crud->field ( 'id' )->title = "編號";
$adm_pwd = $crud->field ( 'adm_pwd' );
$adm_pwd->isPassword = true;
$adm_pwd->encode ( function ($v) {
return md5 ( $ ); } );
$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' => '停用',
'1' => '啟用'
);
$status->title = "狀態";
$status->updateType = 'radio';
$createtime = $crud->field ( 'createtime' );
$createtime->isCreated = true;
$createtime->searchType = 'DateRange';
$createtime->decode ( function ($v) {
return date ( 'Y-m-d H: 'Y-m-d H:' ', intval ( $v ) );
} );
$endtime = $crud->field ( 'endtime' );
$endtime->isUpdated = true;
$endtime->searchType = 'DateRange';
e';
$endtime->decode ( function ($v) {
return date ( 'Y-m-d H:i:s', intval ( $v ) );
} );
// 啟用被禁止的使用者
$enable = $ crud->operationRow ( 'Enable' );
$enable->title = "啟用";
$enable->filter = function ($row) {
return $row ['status'] == 0 and $row [ 'id'] != 1;
};
$enable->do = array($this,'doEnable');
// 停用已啟用的使用者
$disable = $crud->operationRow ( 'Disable' );
$disable->title = "禁用";
$disable->filter = function ($row) {
return $row ['status'] == 1 and $row ['id'] != 1;
};
$disable->do=array($this,'doDisable');
// 權限設定
$auth = $crud->operationRow ( 'setAuth' );
$auth->title = "權限管理";
$auth->filter = function ($row) {
return $row ['status'] == 1 and $row ['id'] != 1;
};
$auth->do= array($this,'doSetAuth');
$tOperation=$crud->operationTable('TOperation');
$tOperation->title="表級操作";
$tOperation->do=array($ this,'tOperation');
$mOperation=$crud->operationMulti('MOperation');
$mOperation->title="多選操作";
$mOperation->confirm=false;
> do=array($this,'mOperation');
$crud->process ( $this->request );
}
public function mOperation(){
echo '測試通用多選操作'
public function mOperation(){
echo '測試通用多選操作'
dump; $this->request->ids);
return array('msg'=>'執行了一個通用多選操作');
}
public function tOperation(){
echo '測試通用表級操作';
return array('msg'=>'執行了一個通用表級操作','go'=>'list');
}
public function doEnable(){
echo '啟用一個用戶';
return array ('msg'=>'啟用了一個使用者','go'=>'list');
}
public function doDisable(){
echo '停用一個使用者';
return array('msg'=> '禁用了一個使用者','go'=>'list');
}
public function doSetAuth(){
echo '設定權限';
}
並不能獨立運作,需要整個框架的支援,但開發人員可從中摘取相應的功能