파일 구조가 아래 형식으로 되어있을때

 

   

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');
}

 

+ 최근 게시물