Files
finanzen/app/Controllers/Accounts.php
Markus 995e2ec111 redesign for mulituser
change validation concept (client and server)
using entities
2026-10-06 08:55:35 +02:00

44 lines
1.2 KiB
PHP

<?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]);
}
};