Codeigniter

Git-hub

https://github.com/braverokmc79/Codeigniter_project2

 

list_v.php

<?php		
		foreach ($list as $lt ) {
		?>
		<tr>
			<th scope="row">
				<?php echo $lt->board_id; ?>
			</th>
			<td>
	<a rel="external" 
	href="/todo/<?php echo $this->uri->segment(1);?>/view/<?php  echo $lt->board_id; ?>/<?php echo $this->uri->segment(3);?>/<?php echo $this->uri->segment(4);?>/<?php echo $this->uri->segment(5);?>" >

			<?php echo $lt->subject; ?></a></td>
			<td><?php echo  $lt->user_name; ?></td>
			<td><?php echo $lt->hits; ?></td>
			<td>
			<time datetime="<?php echo mdate("%Y. %m. %j" ,human_to_unix($lt->reg_date)); ?>" >
			<?php echo mdate( "%Y. %m. %j ", human_to_unix($lt->reg_date)); ?></time></td>

		</tr>
	<?php		
		}
	?>

 

 

board.php

 

	class Board extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		//$this->load->database();
		$this->load->model('board_m');
		$this->load->helper(array('url', 'date'));
	}


	/*
		주소에서 메서드가 생략되었을 때 실행되는 기본 메서드
	 */
	public function index()
	{
		$this->lists();
	}


	/*
		사이트 헤더, 푸터가 자동으로 추가 된다.
	 */
	public function _remap($method)
	{
		//헤더 include
		$this->load->view('header_v');

		if(method_exists($this, $method))
		{
			$this->{"{$method}"}();
		}	

		//푸터 include
		$this->load->view('footer_v');
	}




/*
		게시물 수정
	*/
	 function modify()
	 {
	 	//경고창 헬퍼 로딩
	 	$this->load->helper('alert');
	 	echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';

	 	if($_POST)
	 	{
	 		//글 수정 POST 전송 시
	 		
	 		//주소 중에서 page 세그먼트가 있는지 검사하기 위해 주소를 배열로 변환
	 		$pages=1;
	 		if(!is_null($this->uri->segment(7) ))
	 		{
			
		 		$uri_array=$this->segment_explode($this->uri->uri_string());

		 		if(in_array('page', $uri_array))
		 		{
		 			$pages=urldecode($this->url_explode($uri_array, 'page'));
		 		}
		 		

	 		}

	 		if(!$this->input->post('subject', TRUE) OR !$this->input->post('contents', TRUE))
	 		{
	 			//글 내용이 없을 경우, 프로그램단에서 한 번 더 체크
	 			alert('비정상적인 접근입니다.', '/todo/board/view/'.$this->uri->segment(3));
				exit;	
	 		}

	 		//var_dumbp($_POST)
	 		$modify_data=array(
	 				'table' =>'ci_board',
	 				'board_id'=>$this->uri->segment(4), //게시물 번호
	 				'subject' =>$this->input->post('subject', TRUE),
	 				'contents' =>$this->input->post('contents', TRUE)
	 		);

/*	 		foreach ($modify_data as $key => $value) {
	 			echo $value;	# code...
	 		};
	 		
	 		exit;*/

	 		$result=$this->board_m->modify_board($modify_data);

	 		if($result)
	 		{

	 			//글 작성 성공 시 게시물 목록으로
	 			alert('수정되 었습니다.', '/todo/board/lists/ci_board/page/'.$pages);
				exit;	
	 		}
	 		else
	 		{
	 			//글 수정 실패 시 글 내용으로
	 			alert('다시 수정 해 주세요.', '/todo/board/lists/ci_board/page/'.$pages);
				exit;	
	 		}

	 	}else{

			// GET 방식일 경우 게시물 내용 가져 오기
	 		$data['views']=$this->board_m->get_view($this->uri->segment(4));

	 		//쓰기 폼 view 호출
	 		$this->load->view('board/modify_v', $data);
	 	}
	 }

 

board_m.php

/*
	게시물 수정

	*/
	function modify_board($arrays)
	{
		$modify_array=array(
				'subject'=>$arrays['subject'],
				'contents'=>$arrays['contents']
			);

		$where=array(
				'board_id'=>$arrays['board_id']
			);

		$result=$this->db->update($arrays['table'], $modify_array, $where);

		//결과 반환
		return $result;
	}

 

 

 

modify_v.php

<article id="board_area">
	<header>
		<h1></h1>
	</header>
	
	<form class="form-horizontal" method="post" action="" id="write_action">
		<fieldset>
			<legend>게시물 수정</legend>		
				<div class="control-group">
				<label class="controls-label" for="input01">제목</label>
				<div class="controls">
					<input type="text" class="input-xlarge" id="input01" name="subject"
					 value="<?php echo $views->subject; ?>">
					
				</div>
		
				
			<label class="controls-label" for="input02">내용</label>
				<div class="controls">
<textarea class="input-xlarge" id="input02" name="contents" rows="5"><?php echo $views->contents; ?></textarea>
			
			<p class="help-block">게시물의 내용을 써주세요.</p>
			</div>
			
			<div class="form-actions">
				<button type="button" class="btn btn-primary" id="write_btn">작성</button>
				<button class="btn"  onclick="document.location.reload()">취소</button>
			</div>
		</fieldset>
	</form>
	

</article>

<script type="text/javascript">
	
$(document).ready(function(){

	$("#write_btn").click(function(){
				
		if($("#input01").val()==''){
			alert('제목을 입력해주세요');
			$('#input01').focus();
			return ;
		
		}else if($("#input02").val()==''){
			alert("내용을 입력해주세요.");
			$("#input02").focus();

			return ;
		}else{
			$("#write_action").submit();
		}


	});

});

</script>

 

 

 

 

 

 

about author

PHRASE

Level 60  머나먼나라

동은 형체의 거울이고, 술은 마음의 거울이다. -에스킬루스

댓글 ( 4)

댓글 남기기

작성

Codeigniter 목록    more