2016-04-13 23 views
0

CodeIgniter2 kullanıyorum. Url bölümlerini bir denetleyiciye ve yönteme yönlendirmek için yönlendirme kullanıyorum.CodeIgniter, sayfa bulunduğunda neden/nerede bir 404 http durumu belirler?

Bu işe yarıyor gibi görünüyor. Sayfalarım beklendiği gibi yükleniyor, yani URL, sayfa bilgisini veritabanından almak, geri gelmek ve doğru sayfayı görüntülemek için doğru yönteme gidiyor. Benim routes.php ilgili kodudur:

$route['default_controller'] = "content"; 
$route['en/(:num)/(:any)'] = "content/en/$1"; 
$route['de/(:num)/(:any)'] = "content/de/$1"; 
$route['es/(:num)/(:any)'] = "content/es/$1"; 
$route['it/(:num)/(:any)'] = "content/it/$1"; 
$route['ar/(:num)/(:any)'] = "content/ar/$1"; 
$route['404_override'] = ''; 

ANCAK yerine 200 http durumunu gösteren görüntülenir sayfa, bu 404 http durumunu gösterir ... Ben neden hiçbir fikrim yok.

Özel bir hata sayfası vermek zorunda olduğum bir MY_Router.php dosyası ile ilgili olduğundan şüpheleniyorum ama neler olduğunu anlayamıyorum.

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class MY_Router extends CI_Router { 

    var $error_controller = 'error'; 
    var $error_method_404 = 'error_404'; 

    function My_Router() 
    { 
     parent::CI_Router(); 
    } 

    // this is just the same method as in Router.php, with show_404() replaced by $this->error_404(); 
    function _validate_request($segments) 
    { 
     // Does the requested controller exist in the root folder? 
     if (file_exists(APPPATH.'controllers/'.$segments[0].EXT)) 
     { 
      return $segments; 
     } 

     // Is the controller in a sub-folder? 
     if (is_dir(APPPATH.'controllers/'.$segments[0])) 
     {  
      // Set the directory and remove it from the segment array 
      $this->set_directory($segments[0]); 
      $segments = array_slice($segments, 1); 

      if (count($segments) > 0) 
      { 
       // Does the requested controller exist in the sub-folder? 
       if (! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT)) 
       { 
        return $this->error_404(); 
       } 
      } 
      else 
      { 
       $this->set_class($this->default_controller); 
       $this->set_method('index'); 

       // Does the default controller exist in the sub-folder? 
       if (! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT)) 
       { 
        $this->directory = ''; 
        return array(); 
       } 
      } 

      return $segments; 
     } 

     // Can't find the requested controller... 
     return $this->error_404(); 
    } 

    function error_404() 
    { 
     $this->directory = ""; 
     $segments = array(); 
     $segments[] = $this->error_controller; 
     $segments[] = $this->error_method_404; 
     return $segments; 
    } 

    function fetch_class() 
    { 
     // if method doesn't exist in class, change 
     // class to error and method to error_404 
     $this->check_method(); 

     return $this->class; 
    } 

    function check_method() 
    { 
     $ignore_remap = true; 

     $class = $this->class; 
     if (class_exists($class)) 
     { 
      // methods for this class 
      $class_methods = array_map('strtolower', get_class_methods($class)); 

      // ignore controllers using _remap() 
      if($ignore_remap && in_array('_remap', $class_methods)) 
      { 
       return; 
      } 

      if (! in_array(strtolower($this->method), $class_methods)) 
      { 
       $this->directory = ""; 
       $this->class = $this->error_controller; 
       $this->method = $this->error_method_404; 
       include(APPPATH.'controllers/'.$this->fetch_directory().$this->error_controller.EXT); 
      } 
     } 
    } 

    function show_404() 
    { 
     include(APPPATH.'controllers/'.$this->fetch_directory().$this->error_controller.EXT); 
     call_user_func(array($this->error_controller, $this->error_method_404)); 
    } 

} 

/* End of file MY_Router.php */ 
/* Location: ./system/application/libraries/MY_Router.php */ 
+0

İlgili olup olmadığından emin değilsiniz, ancak 'MY_Router' kodu CI <= 1.7 sürümüne aittir. – Tpojka

+0

Teşekkürler Tpojka - bunu nasıl biliyorsunuz ve yükseltilmiş bir sürümünü nereden alabileceğimi biliyor musunuz? işe yarayabilir, olmayabilir! teşekkürler –

+0

Sözdizimi nedeniyle. Yıllar önce "var" ile mülkler ilan edildi. Bunu görünürlük beyanı ile ihmal edebilirsiniz (kontrol edin [burada] (http://php.net/manual/en/language.oop5.properties.php)). İkinci şey kurucu. Public function __construct() { parent :: __ construct();} 'olmalıdır. PHP [docs] (http://php.net/manual/en/language.oop5.decon.php). Bunu başlangıç ​​için değiştirin. – Tpojka

cevap

0

Çözüldü - sitede entegre wordpress blog olmayan tüm wordpress sayfaları için 404 statüsünü batıyordu yani CodeIgniter'ın sayfalar

CI

index.php

dışarı yorumladı gereken aşağıdaki kodu vardı
/* 
*--------------------------------------------------------------- 
* WORDPRESS INTEGRATION 
*--------------------------------------------------------------- 
* The ci_site_url function helps to avoid collision between WP & CI. 
*/ 

//header("HTTP/1.0 200 OK"); 

define('WP_USE_THEMES', false); 
require_once './blog/wp-blog-header.php'; 

add_filter('site_url', 'ci_site_url', 1); 

    function ci_site_url() 
    { 
    include(APPPATH.'/config/config.php'); 
    return $config['base_url']; 
    }