2016-06-23 49 views
1

沒有顯示我有一個頁面是由ID訪問e.g http:/localhost/v2/indicator/details/directives/4404頁的笨

但是當我刪除id e.g http:/localhost/v2/indicator/details/directiveshttp:/localhost/v2/indicator/details/directives/mail.html它仍試圖訪問該頁面,並給我的錯誤。 我希望它給我一個404找不到頁面,我有。

錯誤

Message: Missing argument 2 for Indicator::details() 

Filename: controllers/Indicator.php 

Line Number: 140 

Backtrace: 

File: C:\wamp\www\v2\application\controllers\Indicator.php Line: 140 
Function: _error_handler 

File: C:\wamp\www\v2\index.php Line: 315 Function: require_once 
Severity: Notice 

Message: Undefined variable: id 

Filename: controllers/Indicator.php 

Line Number: 154 

Backtrace: 

File: C:\wamp\www\v2\application\controllers\Indicator.php Line: 154 
Function: _error_handler 

File: C:\wamp\www\v2\index.php Line: 315 Function: require_once 

對於細節

控制器部
public function details($directive, $id) { 

     $this->data['current_user_menu'] = ''; 
     if($this->ion_auth->in_group('admin')) 
     { 


     $data['user'] = $this->ion_auth->user()->row(); 
     $data['indicators'] = $this->core->getIndicators(); 
     // load views and send data 
     $this->data['current_user_menu'] = $this->load->view('header', $data); 
     $this->data['current_user_menu'] = $this->load->view('templates/view_indicator', $data); 
     $this->data['current_user_menu'] = $this->load->view('footer_main'); 
     } 
     else 
     { 
     //If no session, redirect to login page 
     redirect('auth/login'); 
     } 
    } 

視圖有

<?php $in_id = $this->uri->segment(4);?> 

自定義404控制器

class My404 extends CI_Controller 
{ 
    public function __construct() 
    { 
     parent::__construct(); 
    } 

    public function index() 
    { 
     $this->layout->set_body_attr(array('class' => 'gray-bg')); 

     $this->layout->add_css_files(array('bootstrap.min.css'), base_url().'assets/css/'); 
     $this->layout->add_css_files(array('font-awesome.css'), base_url().'assets/font-awesome/css/'); 
     $this->layout->add_css_files(array('animate.css','style.css'), base_url().'assets/css/'); 
     $this->output->set_status_header('404'); 
     $this->load->view('404');//loading in my template 
    } 
} 
+1

我們不能做你的代碼,你應該張貼您的'指標::細節()'控制器的代碼。 –

+0

@ArshSingh我已經做了一些編輯,如果這會對我有幫助 –

回答

2

嘗試這樣

功能

  1. is_int in php.net
  2. empty in php.net
  3. show_404 in codeigniter.com

在指標控制器

public function details($directive, $id) { 

    if (!is_int($id) || empty($id)) 
    { 
     show_404(); 
    } 
    else { 
     $this->data['current_user_menu'] = ''; 
     if($this->ion_auth->in_group('admin')) 
     { 
      $data['user'] = $this->ion_auth->user()->row(); 
      $data['indicators'] = $this->core->getIndicators(); 
      // load views and send data 
      $this->data['current_user_menu'] = $this->load->view('header', $data); 
      $this->data['current_user_menu'] = $this->load->view('templates/view_indicator', $data); 
      $this->data['current_user_menu'] = $this->load->view('footer_main'); 
     } 
     else 
     { 
      //If no session, redirect to login page 
      redirect('auth/login'); 
     } 
    } 
} 
+0

我會讓$ $ id參數爲可選參數,因爲這似乎是問題的關鍵。 '公共函數的詳細信息($指令,$ id = null)' –

+0

我的404是自定義的,並有一個控制器...我怎麼稱呼它。 **看到編輯** –

+0

使用**重定向**就像這樣''redirect('auth/login');' –