trafficmonitor init...2
This commit is contained in:
parent
9672a7d4da
commit
d86c64b28e
@ -25,31 +25,15 @@ class LocalForm extends CommonForm
|
||||
}
|
||||
public function getFormRule(string $action, string $field, array $rules = []): array
|
||||
{
|
||||
// 부모 클래스의 기본 규칙을 먼저 가져옵니다.
|
||||
$rules = parent::getFormRule($action, $field, $rules);
|
||||
|
||||
switch ($field) {
|
||||
case "id":
|
||||
// 💡 배열을 사용하여 규칙 목록을 안전하게 만듭니다.
|
||||
$ruleList = [
|
||||
"required",
|
||||
"trim",
|
||||
"min_length[4]",
|
||||
"max_length[20]",
|
||||
];
|
||||
// 'create' 액션에만 is_unique 규칙을 추가합니다.
|
||||
if (in_array($action, ["create", "create_form"])) {
|
||||
// $this->getAttribute('table') 대신 $this->model->getTable()를 사용하거나,
|
||||
// 해당 Form 클래스가 $this->model을 가지고 있다면 그것을 사용해야 합니다.
|
||||
$ruleList[] = "is_unique[{$this->getAttribute('table')}.{$field}]";
|
||||
}
|
||||
// 배열 요소를 '|'로 안전하게 연결하여 최종 Rule 문자열을 생성합니다.
|
||||
$rules[$field] = implode('|', $ruleList);
|
||||
$rule = "required|trim|min_length[4]|max_length[20]";
|
||||
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
||||
$rules[$field] = $rule;
|
||||
break;
|
||||
case "passwd":
|
||||
$rules[$field] = in_array($action, ["create", "create_form"])
|
||||
? "required|trim|string"
|
||||
: "permit_empty|trim|string";
|
||||
$rules[$field] = in_array($action, ["create", "create_form"]) ? "required|trim|string" : "permit_empty|trim|string";
|
||||
break;
|
||||
default:
|
||||
$rules = parent::getFormRule($action, $field, $rules);
|
||||
|
||||
@ -22,17 +22,23 @@ class UserHelper extends CommonHelper
|
||||
if (($viewDatas['control']['entity'] ?? null) instanceof UserEntity) {
|
||||
$value = $viewDatas['control']['entity']->getRole();
|
||||
}
|
||||
dd($value);
|
||||
$currentRoles = is_array($value)
|
||||
? array_map('strtolower', array_map('trim', $value))
|
||||
: [];
|
||||
$form = '';
|
||||
//체크박스를 순회하며 생성
|
||||
foreach ($viewDatas['control']['formOptions']['role'] as $roleValue => $roleLabel) {
|
||||
$checked = in_array(strtolower(trim($roleValue)), $currentRoles);
|
||||
foreach ($viewDatas['control']['formOptions']['role'] as $key => $label) {
|
||||
$checked = in_array(strtolower(trim($key)), $currentRoles);
|
||||
var_dump($currentRoles);
|
||||
echo '<HR>';
|
||||
echo $key;
|
||||
echo $checked ? "{$key}TRUE" : "FALSE";
|
||||
dd($viewDatas['control']['formOptions']['role']);
|
||||
$form .= '<label class="me-3">';
|
||||
// form_checkbox에 들어가는 값($roleValue)은 원본 값을 유지(저장용).
|
||||
$form .= form_checkbox('role[]', $roleValue, $checked, array_merge(['id' => "role_{$roleValue}"], $extras));
|
||||
$form .= " {$roleLabel}";
|
||||
// form_checkbox에 들어가는 값($key)은 원본 값을 유지(저장용).
|
||||
$form .= form_checkbox('role[]', $key, $checked, array_merge(['id' => "role_{$key}"], $extras));
|
||||
$form .= " {$label}";
|
||||
$form .= '</label>';
|
||||
}
|
||||
break;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user