2016-05-11 8 views
0

PHP7とNginxを使用して、PHP4を使用して2.0x CodeIgniterを3.0.6にアップグレードするように私は任されています。私は文書化されたupgrade processに従っています。CodeIgniter、Controllerの現在のURLを取得していますか?

私が遭遇している問題は、$this->uriという値が、既存のページが今は迷惑メールのように見えるということです。

require("App_Controller.php"); 
class StaticContent extends AppController { 

    function index() { 
    error_log('A>>>' . serialize($this->uri->uri_string()) . '<<<'); 
    } 

    function _remap() { 

    // These two lines added for analysing issue 
    $this->index(); 
    return; 

    // TODO: Temporary - Hard coded splash page to use an empty template 
    if($this->uri->segment(1) === false && $pageData = $this->contentmodel->get(NULL, -1, 'empty')) { 
     $this->_locale_splash(); 
    } 
    elseif(substr($this->uri->uri_string(), -1, 1) != '/') { 
     // Add trailing slash if not present 
     redirect2($this->uri->uri_string() . '/'); 
    } 
    // other code omitted 
    } 

} 

ログのテキスト出力:

"PHP message: A>>>s:0:"";<<<" while reading response header from upstream, client: 10.0.2.2, server: _, request: "GET /2017/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "localhost:8080" 

私はs:0:"";値を作るために何を知らないか、私はどうあるべきか、他のロジックなし

コード、この問題を解決するには?スパーキーの提案、http://localhost:8080/2017/ためvar_dump($this->uri)出力(CodeIgniterのは2017年のパスに住んでいる)@続き

は、与えられる:

object(CI_URI)#6 (6) { 
    ["keyval"]=> 
    array(0) { 
    } 
    ["uri_string"]=> 
    string(0) "" 
    ["segments"]=> 
    array(0) { 
    } 
    ["rsegments"]=> 
    array(2) { 
    [1]=> 
    string(13) "staticcontent" 
    [2]=> 
    string(5) "index" 
    } 
    ["_permitted_uri_chars":protected]=> 
    string(14) "a-z 0-9~%.:_\-" 
    ["config"]=> 
    &object(CI_Config)#3 (3) { 
    ["config"]=> 
    &array(55) { 
     ["OT_front_news_count"]=> 
     int(8) 
     ["OT_show_countdown"]=> 
     bool(true) 
     ["OT_show_newsletter"]=> 
     bool(false) 
     ["OT_event_date_en"]=> 
     string(18) "August 5–7, 2017" 
     ["OT_event_date_fr"]=> 
     string(18) "5 – 7 août 2017" 
     ["OT_event_year"]=> 
     string(4) "2016" 
     ["site_name"]=> 
     string(14) "MySite 2017" 
     ["base_url"]=> 
     string(26) "http://localhost:8080/2017" 
     ["index_page"]=> 
     string(0) "" 
     ["uri_protocol"]=> 
     string(11) "REQUEST_URI" 
     ["url_suffix"]=> 
     string(0) "" 
     ["language"]=> 
     string(7) "english" 
     ["charset"]=> 
     string(5) "UTF-8" 
     ["enable_hooks"]=> 
     bool(false) 
     ["subclass_prefix"]=> 
     string(3) "MY_" 
     ["composer_autoload"]=> 
     bool(false) 
     ["permitted_uri_chars"]=> 
     string(14) "a-z 0-9~%.:_\-" 
     ["allow_get_array"]=> 
     bool(true) 
     ["enable_query_strings"]=> 
     bool(false) 
     ["controller_trigger"]=> 
     string(1) "c" 
     ["function_trigger"]=> 
     string(1) "m" 
     ["directory_trigger"]=> 
     string(1) "d" 
     ["log_threshold"]=> 
     int(0) 
     ["log_path"]=> 
     string(0) "" 
     ["log_file_extension"]=> 
     string(0) "" 
     ["log_file_permissions"]=> 
     int(420) 
     ["log_date_format"]=> 
     string(11) "Y-m-d H:i:s" 
     ["error_views_path"]=> 
     string(0) "" 
     ["cache_path"]=> 
     string(0) "" 
     ["cache_query_string"]=> 
     bool(false) 
     ["encryption_key"]=> 
     string(0) "" 
     ["sess_driver"]=> 
     string(5) "files" 
     ["sess_cookie_name"]=> 
     string(10) "ci_session" 
     ["sess_expiration"]=> 
     int(7200) 
     ["sess_save_path"]=> 
     NULL 
     ["sess_match_ip"]=> 
     bool(false) 
     ["sess_time_to_update"]=> 
     int(300) 
     ["sess_regenerate_destroy"]=> 
     bool(false) 
     ["cookie_prefix"]=> 
     string(0) "" 
     ["cookie_domain"]=> 
     string(0) "" 
     ["cookie_path"]=> 
     string(6) "/2016/" 
     ["cookie_secure"]=> 
     bool(false) 
     ["cookie_httponly"]=> 
     bool(false) 
     ["standardize_newlines"]=> 
     bool(false) 
     ["global_xss_filtering"]=> 
     bool(false) 
     ["csrf_protection"]=> 
     bool(false) 
     ["csrf_token_name"]=> 
     string(14) "csrf_test_name" 
     ["csrf_cookie_name"]=> 
     string(16) "csrf_cookie_name" 
     ["csrf_expire"]=> 
     int(7200) 
     ["csrf_regenerate"]=> 
     bool(true) 
     ["csrf_exclude_uris"]=> 
     array(0) { 
     } 
     ["compress_output"]=> 
     bool(false) 
     ["time_reference"]=> 
     string(5) "local" 
     ["rewrite_short_tags"]=> 
     bool(false) 
     ["proxy_ips"]=> 
     string(0) "" 
    } 
    ["is_loaded"]=> 
    array(0) { 
    } 
    ["_config_paths"]=> 
    array(1) { 
     [0]=> 
     string(31) "/var/www/html/2017/application/" 
    } 
    } 
} 
+0

なぜ '1'を' uri_string() 'に渡していますか? – Sparky

+0

'$ this-> uri-> uri_string()'を 'echo'または' var_dump() 'で調べましたか? – Sparky

+0

この例では、1はtypoであり、例を更新しました。エコーの代わりに '' 'error_log()' ''を使っていました。私が最初に気付いたのは、elseifが入力されていて、CodeIgniter 2.0.xのインストール時に発生しなかった余分な「/」を追加したことが原因です。 var_dump($ this-> uri_string()) '' 'は' '' string(0) "" '' 'を返し、' '' var_dump($ this-> uri) ''はより構造化された出力。上記で更新します。 –

答えて

0

をごhttp://localhost:8080/2017/var_dump($this->uri) ...

object(CI_URI)#6 (6) { 
    ["keyval"]=> 
    array(0) { 
    } 
    ["uri_string"]=> 
    string(0) "" 
    ["segments"]=> 
    array(0) { 
    } 
    .... 

によると...あなたのURIにはセグメントがありません(2017/の後には何もありません)ので、""はURI文字列の期待される結果です。


According to the docs

uri_string()

戻り値:URI文字列

戻り値の型:文字列

は、完全なURIを持つ文字列を返します。これはあなたの完全なURLであれば、例えば:

news/local/345

http://example.com/index.php/は、URI文字列の一部ではありませんどのように注意してください:

http://example.com/index.php/news/local/345

方法は、これを返します。

関連する問題