docs: add project docs and test updates

This commit is contained in:
taekyoungc
2026-04-08 00:23:55 +09:00
parent 06fedc866a
commit 06aa401048
238 changed files with 8373 additions and 148 deletions

View File

@@ -0,0 +1,50 @@
# 개발 스타일 (Development Style)
> Auth 프로젝트(`Auth.php`, `auth/login.php`, `MemberModel`)를 기준으로 한 개발 스타일. AI 생성 코드는 이 스타일을 따른다.
## 1. 요청 흐름
- **GET**: 폼 표시 또는 목록 조회 → `view('폴더/파일')` 반환.
- **POST**: 유효성 검사 → Model 호출 → 성공 시 `redirect()->to(...)->with('success', ...)`, 실패 시 `redirect()->back()->withInput()->with('error'|'errors', ...)`.
## 2. 컨트롤러 메서드 패턴
| 용도 | 메서드명 예시 | 동작 |
|------|----------------|------|
| 폼 표시 | `showLoginForm()`, `create()`, `edit($id)` | `return view('auth/login');` 등 |
| 처리 | `login()`, `store()`, `update($id)`, `delete($id)` | `$this->validate()` → Model → `redirect()` |
- 폼 표시 메서드는 가능하면 `showXxxForm()` 또는 리소스형 `index`, `create`, `edit` 사용.
- 처리 메서드는 동사형(`login`, `store`, `update`, `delete`).
## 3. 유효성 검사
- 규칙·메시지는 배열로 정의, 한글 메시지 사용.
- 실패 시: `redirect()->back()->withInput()->with('errors', $this->validator->getErrors())`.
- 단일 에러 메시지는 `with('error', '메시지')`.
```php
$rules = ['login_id' => 'required|max_length[50]', ...];
$messages = ['login_id' => ['required' => '아이디를 입력해 주세요.', ...]];
if (! $this->validate($rules, $messages)) {
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
}
```
## 4. Model 사용
- `model(MemberModel::class)` 형태로 로드.
- 조회·추가·수정·삭제는 Model 메서드에 위임. 컨트롤러에서 직접 쿼리 빌더 노출 최소화.
## 5. 리다이렉트
- 성공: `redirect()->to(site_url('/'))->with('success', '...')` 또는 `redirect()->to('login')->with('success', '...')`.
- 실패: `redirect()->back()->withInput()->with('error', '...')` 또는 `with('errors', ...)`.
- 내부 URL은 `site_url()` 또는 `base_url()` 사용.
## 6. 뷰 공통
- 출력 시 `esc()` 사용. 폼에는 `csrf_field()`, `old('필드명')` 사용.
- 플래시: `session()->getFlashdata('success')`, `getFlashdata('error')`, `getFlashdata('errors')` 표시.
이 스타일을 유지하면 Auth와 동일한 톤으로 확장된다.