2013-08-31 2 views
0

데이터베이스에서 내용 페이지를 삭제하려고 시도하는 중 오류 또는 성공 메시지를 알리는 메시지를 사용자에게 표시하는 방법을 배우고 있습니다. 나는 "바로 지금까지 그 일을 해요 궁금 해요. 내가하면 어떻게 내가보기에 무엇을?Codeigniter의 flashdata에서 성공/실패 메시지 표시

컨트롤러

/** 
* Content_pages::delete_content_page() 
* 
* Deletes a content page from the list of content pages. 
* 
* @param string $content_page_id The id of the content page being deleted. 
* @return void 
*/ 
public function delete_content_page($content_page_id) 
{ 
    $status = 'unprocessed'; 
    $title = 'Action Unprocessed'; 
    $message = 'The last action was rendered unprocessed. Please try again.'; 
    if (isset($content_page_id) && is_numeric($content_page_id)) 
    { 
     $content_page_data = $this->content_page->get($content_page_id); 
     if (!empty($content_page_data)) 
     { 
      $this->content_page->update($content_page_id, array('status_id' => 3)); 
      if ($this->db->affected_rows() > 0) 
      { 
       $status = 'success'; 
       $message = 'The content page has been successfully deleted.'; 
       $title = 'Content Page Deleted'; 
      } 
      else 
      { 
       $status = 'error'; 
       $message = 'The content page was not deleted successfully.'; 
       $title = 'Content Page Not Deleted'; 
      } 
     } 
    } 
    $output = array('status' => $status, 'message' => $message, 'title' => $title); 
    $this->session->set_flashdata('output', $output); 
    redirect('content-pages/list'); 
} 

/** 
* Content_pages::list_content_pages() 
* 
* List all of the content pages found in the database. 
* 
* @return void 
*/ 
public function list_content_pages() 
{ 
    $content_pages = $this->content_page->get_all(); 

    $data['output'] = $this->session->flashdata('output'); 

    $this->template 
     ->title('Content Pages') 
     ->set('content_pages', $content_pages) 
     ->build('content_pages_view', $data);  
} 

비어 기본값으로 나타 때문에 내 문제는보기에 내가보기 먼저 렌더링하고있는 경우에만 메시지가 표시 될 때를 보여주지하는 방법을 알아 내려고 노력하고있어 수 있도록 메시지.

if (isset($output)) 
{ 
    if ($output['status'] == 'success') 
    { 
     echo '<div class="alert alert-success">'; 
    } 
    elseif ($output['status'] == 'error') 
    { 
     echo '<div class="alert alert-error">'; 
    } 
    else 
    { 
     echo '<div class="alert alert-error">'; 
    } 

    echo '<button type="button" class="close" data-dismiss="alert">&times;</button>'; 
    echo '<strong>' . $output['title'] . '</strong>' . $output['message']; 
    echo '</div>'; 
} 
?> 
+0

보기에서'echo $ output' 만하면됩니다. – rgin

답변

0

데이터가 설정되지 않은 경우 반환되는 값 때문에이 경우 처음로드 될 때 세션 플래시 데이터 값으로 기본값을 설정했습니다. 그래서 값이 거짓인지 확인하기 위해 조건을 추가해야했습니다.

1

나는 사용자 지정 템플릿 클래스는 ->title()->set()->build()로 무엇 확실하지 않다 . 그러나 당신은 여전히 ​​$data을 당신에게 넘기고있는 것처럼 보입니다. 보기.

그래서, 당신은 단지 echo $output;을보기 만하면됩니다.

편집 :

나는 코드 줄은 if 문에 있지 있기 때문에 $output가 여전히 표시하기위한 이유는 생각 :

echo '<button type="button" class="close" data-dismiss="alert">&times;</button>'; 
echo '<strong>' . $output['title'] . '</strong>' . $output['message']; 
echo '</div>'; 

은 if 문 내부를 옮겨보십시오 곳을 $output이 설정된 경우에만 인쇄됩니다.

+0

그러나 고맙습니다. 저는 내보기 코드를 지적하고 싶었습니다. 표시 할 메시지를 확인하기 위해 if 문만 보여 주었지만 항상 발생하지 않아야하는 뷰 렌더링에 항상 표시됩니다. 수표로 if 문에 무엇을 추가해야합니까? – user2576961

+0

내 수정 된 답변을 확인하십시오. – rgin

+0

if 문 안에 있음을 확인하면. – user2576961

관련 문제