파일 구조가 아래 형식으로 되어있을때
app
Controllers
User
Home
View
User
insert
Config
Routes
Home.php
<?php namespace App\Controllers;
class Home extends BaseController
{
public function index()
{
return view('welcome_message');
}
//--------------------------------------------------------------------
public function save($id = ''){
$user_model = model('UserModel');
if ( $id )
{
// Updating
$user = $user_model->find($user_id);
$user_post = new Board( $this->request->getPost());
$user->name = $user_post->name;
$user->passwd = $user_post->passwd;
$user->email = $user_post->email;
}else {
// Create
$user = new BoardArticle($this->request->getPost());
$user->name = $user->name;
$user->passwd = $user->passwd;
$user->email = $user->email;
}
$user_model->save($board);
return redirect()->route('/');
}
}
Routes.php에 추가
$routes->group('board', function($routes) {
$routes->post('/', 'Board');
$routes->post('save', 'Board\Home::save');
$routes->post('save/(:num)', 'Board\Home::save/$1');
}
'IT > PHP' 카테고리의 다른 글
코드이그나이터4 파일 다운로드 - CodeIgniter4 file download (0) | 2020.08.19 |
---|---|
PHP 배열합치기 array() (0) | 2020.05.19 |
PHP Blocked a frame with origin "https://" from accessing a cross-origin frame. Error(오류) (0) | 2020.05.19 |