반응형
게시판에 필요한 다른 파일들도 만들어보자. 글쓰기와 글보기 페이지다.
제일 먼저 라우트를 수정한다.
/app/Config/Routes.php
<?php
namespace Config;
// Create a new instance of our RouteCollection class.
$routes = Services::routes();
// Load the system's routing file first, so that the app and ENVIRONMENT
// can override as needed.
if (is_file(SYSTEMPATH . 'Config/Routes.php')) {
require SYSTEMPATH . 'Config/Routes.php';
}
/*
* --------------------------------------------------------------------
* Router Setup
* --------------------------------------------------------------------
*/
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
// The Auto Routing (Legacy) is very dangerous. It is easy to create vulnerable apps
// where controller filters or CSRF protection are bypassed.
// If you don't want to define all routes, please use the Auto Routing (Improved).
// Set `$autoRoutesImproved` to true in `app/Config/Feature.php` and set the following to true.
// $routes->setAutoRoute(false);
/*
* --------------------------------------------------------------------
* Route Definitions
* --------------------------------------------------------------------
*/
// We get a performance increase by specifying the default
// route since we don't have to scan directories.
$routes->get('/', 'Home::index');
$routes->get('/board', 'Board::list');
$routes->get('/boardWrite', 'Board::write');
$routes->get('/boardView', 'Board::view');
/*
* --------------------------------------------------------------------
* Additional Routing
* --------------------------------------------------------------------
*
* There will often be times that you need additional routing and you
* need it to be able to override any defaults in this file. Environment
* based routes is one such time. require() additional route files here
* to make that happen.
*
* You will have access to the $routes object within that file without
* needing to reload it.
*/
if (is_file(APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php')) {
require APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php';
}
$routes->get('/boardWrite', 'Board::write');
$routes->get('/boardView', 'Board::view');
위 두줄을 추가했다. 이제 이걸 보면 무엇을 해야 하는지 알아야한다. 컨트롤러에 가보자.
/app/Controllers/Board.php
<?php
namespace App\Controllers;
class Board extends BaseController
{
public function list()
{
return render('board_list');
}
public function write()
{
return render('board_write');
}
public function view()
{
return render('board_view');
}
}
요렇게 추가해줬다. 그럼 다음엔 무엇을 해야 할까? View밑에 파일을 만들면 된다.
/app/Views/board_write.php
<form method="post" action="<?= site_url('/write_save') ?>" enctype="multipart/form-data">
<div class="mb-3">
<label for="exampleFormControlInput1" class="form-label">제목</label>
<input type="text" name="subject" class="form-control" id="exampleFormControlInput1" placeholder="제목을 입력하세요." value="">
</div>
<div class="mb-3">
<label for="exampleFormControlTextarea1" class="form-label">내용</label>
<textarea class="form-control" id="exampleFormControlTextarea1" name="content" rows="3"></textarea>
</div>
<br />
<button type="submit" class="btn btn-primary">등록</button>
</form>
/app/Views/board_view.php
<h3 class="pb-4 mb-4 fst-italic border-bottom" style="text-align:center;">
- 게시판 보기 -
</h3>
<article class="blog-post">
<h2 class="blog-post-title">제목이 오는 곳</h2>
<p class="blog-post-meta">날짜 by <a href="#">글쓴이</a></p>
<hr>
<p>
내용이 오는 곳
</p>
<hr>
</article>
이렇게 만들고 페이지를 열어보자.
http://localhost:8080/boardWrite
http://localhost:8080/boardView
이렇게 나오면 성공이다.
반응형
'PHP강좌 > [CI4]게시판만들기강좌' 카테고리의 다른 글
[PHP+CI4+mysql]게시판 만들기 강좌 #9. 게시판 내용 보기 (0) | 2022.11.01 |
---|---|
[PHP+CI4+mysql]게시판 만들기 강좌 #8. 모델을 사용해서 데이터 가져오기, 게시판 리스트 (0) | 2022.10.31 |
[PHP+CI4+mysql]게시판 만들기 강좌 #6. 파일 준비(include, layout.php) 2편 (0) | 2022.10.26 |
[PHP+CI4+mysql]게시판 만들기 강좌 #5. 몇가지 설정(디비,오류표시,index.php) (0) | 2022.10.26 |
[PHP+CI4+mysql]게시판 만들기 강좌 #4. 파일 준비 1편 (0) | 2022.10.25 |