class Board extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('form_validation');
$this->load->model('board_model');
}
public function index()
{
$this->load->view('board/list');
}
public function create()
{
$this->load->view('board/create');
}
public function store()
{
$this->form_validation->set_rules('title', 'Title', 'required');
$this->form_validation->set_rules('contents', 'Contents', 'required');
if($this->form_validation->run()) {
$this->board_model->store();
redirect('/board/create');
} else {
echo "Error";
}
}
}
<form name="rafa" action="/board/store" method="post">
<table board="1">
<tr>
<th>제목</th>
<td>
<input type="text" name="title" value="" />
</td>
</tr>
<tr>
<th>내용</th>
<td>
<textarea name="contents" rows="8"></textarea>
</td>
</tr>
<tr>
<th>내용</th>
<td>
<th colspan="2">
<input type="submit" value=" 저장 " />
</th>
</td>
</tr>
</table>
</form>
# models/Board_model.php
<?php
class Board_model extends CI_Model {
public function __construct()
{
$this->load->database();
$this->load->helper('url');
}
public function store() {
$data = [
'title' => $this->input->post('title'),
'contents' => $this->input->post('contents'),
'regdate' => date("Y-m-d H:i:s")
];
$result = $this->db->insert('boards', $data);
return $result;
}
}
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '860609',
'database' => 'board',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE,
);
출처 https://www.youtube.com/watch?v=TXHWW4dvFzo