redesign for mulituser
change validation concept (client and server) using entities
This commit is contained in:
44
app/Controllers/Accounts.php
Normal file
44
app/Controllers/Accounts.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\Session\Session;
|
||||
use App\Models\mAccounts;
|
||||
use Config\App;
|
||||
|
||||
class Accounts extends BaseController {
|
||||
private \App\Models\mAccounts $accounts;
|
||||
|
||||
public function __construct() {
|
||||
$this->accounts = new mAccounts;
|
||||
}
|
||||
|
||||
public function index(){
|
||||
if ($this->request->is('post')) {
|
||||
return $this->editAccount();
|
||||
}
|
||||
else
|
||||
return $this->viewAccountsTree();
|
||||
}
|
||||
|
||||
private function viewAccountsTree($data = array()){
|
||||
helper('form');
|
||||
$data = array_merge($data,$this->accounts->getTreeData());
|
||||
$data['ddlist'] = $this->accounts->getDropDownList( 'all', false,true );
|
||||
return view('accountstree',$data);
|
||||
}
|
||||
|
||||
private function editAccount(){
|
||||
$rules = [
|
||||
'description' => 'required',
|
||||
];
|
||||
if (! $this->validate($rules)) {
|
||||
return $this->viewAccountsTree(['errors'=>$this->validator->getErrors()]);
|
||||
}
|
||||
$saveDB = array();
|
||||
if ($this->accounts->saveAccount($this->request->getPost()))
|
||||
$saveDB = ['mode'=>'alert-success','message'=>'Erfolgreich gespeichert'];
|
||||
else
|
||||
$saveDB = ['mode'=>'alert-danger','message'=>'Speichern fehlgeschlagen'];
|
||||
|
||||
return $this->viewAccountsTree(['saveDB'=>$saveDB]);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user