trafficmonitor init...2
This commit is contained in:
parent
9672a7d4da
commit
d86c64b28e
@ -25,34 +25,18 @@ class LocalForm extends CommonForm
|
|||||||
}
|
}
|
||||||
public function getFormRule(string $action, string $field, array $rules = []): array
|
public function getFormRule(string $action, string $field, array $rules = []): array
|
||||||
{
|
{
|
||||||
// 부모 클래스의 기본 규칙을 먼저 가져옵니다.
|
$rules = parent::getFormRule($action, $field, $rules);
|
||||||
$rules = parent::getFormRule($action, $field, $rules);
|
|
||||||
|
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
case "id":
|
case "id":
|
||||||
// 💡 배열을 사용하여 규칙 목록을 안전하게 만듭니다.
|
$rule = "required|trim|min_length[4]|max_length[20]";
|
||||||
$ruleList = [
|
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
||||||
"required",
|
$rules[$field] = $rule;
|
||||||
"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);
|
|
||||||
break;
|
break;
|
||||||
case "passwd":
|
case "passwd":
|
||||||
$rules[$field] = in_array($action, ["create", "create_form"])
|
$rules[$field] = in_array($action, ["create", "create_form"]) ? "required|trim|string" : "permit_empty|trim|string";
|
||||||
? "required|trim|string"
|
|
||||||
: "permit_empty|trim|string";
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$rules = parent::getFormRule($action, $field, $rules);
|
$rules = parent::getFormRule($action, $field, $rules);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $rules;
|
return $rules;
|
||||||
|
|||||||
@ -22,17 +22,23 @@ class UserHelper extends CommonHelper
|
|||||||
if (($viewDatas['control']['entity'] ?? null) instanceof UserEntity) {
|
if (($viewDatas['control']['entity'] ?? null) instanceof UserEntity) {
|
||||||
$value = $viewDatas['control']['entity']->getRole();
|
$value = $viewDatas['control']['entity']->getRole();
|
||||||
}
|
}
|
||||||
|
dd($value);
|
||||||
$currentRoles = is_array($value)
|
$currentRoles = is_array($value)
|
||||||
? array_map('strtolower', array_map('trim', $value))
|
? array_map('strtolower', array_map('trim', $value))
|
||||||
: [];
|
: [];
|
||||||
$form = '';
|
$form = '';
|
||||||
//체크박스를 순회하며 생성
|
//체크박스를 순회하며 생성
|
||||||
foreach ($viewDatas['control']['formOptions']['role'] as $roleValue => $roleLabel) {
|
foreach ($viewDatas['control']['formOptions']['role'] as $key => $label) {
|
||||||
$checked = in_array(strtolower(trim($roleValue)), $currentRoles);
|
$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 .= '<label class="me-3">';
|
||||||
// form_checkbox에 들어가는 값($roleValue)은 원본 값을 유지(저장용).
|
// form_checkbox에 들어가는 값($key)은 원본 값을 유지(저장용).
|
||||||
$form .= form_checkbox('role[]', $roleValue, $checked, array_merge(['id' => "role_{$roleValue}"], $extras));
|
$form .= form_checkbox('role[]', $key, $checked, array_merge(['id' => "role_{$key}"], $extras));
|
||||||
$form .= " {$roleLabel}";
|
$form .= " {$label}";
|
||||||
$form .= '</label>';
|
$form .= '</label>';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user