2016-03-24 10 views
0

私はCodeigniterとPHPでもnoobです。
私がお聞きしたい私は
Codeigniter - 2つのコアクラスを拡張するには

アプリケーション/コア/ MY_some_fileに

システム/コア/ some_file


から2つのクラスを拡張することができますか?


私は文字を禁止しているいくつかのURL用のカスタム例外エラーを作ってみましたので、許可されていない文字があるかどう私のカスタムコントローラにリダイレクトがあるはずです。

ここに私のカスタムコアファイル(MY_URI)です:

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 
class MY_URI extends CI_URI{ 

    function __construct(){ 
     parent::__construct(); 
    } 
    function _filter_uri($str){ 
     if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE) 
     { 
      if (! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", $str)) 
      { 
       $this->load->view('page_not_found_v'); 
      } 
     } 

     // Convert programatic characters to entities 
     $bad = array('$',  '(',  ')',  '%28',  '%29'); 
     $good = array('&#36;', '&#40;', '&#41;', '&#40;', '&#41;'); 

     return str_replace($bad, $good, $str); 
    } 
} 

は、私はそのビューをロードしようとしたが、それはそれをロードすることはできません。

答えて

0

システムワークフローの早い段階にあるため、まだいくつかのオブジェクトに到達することはできません。
カスタムエラーページを使用することができます:
application/errorsフォルダにPHPファイルを作成します。このファイルには、たとえばerror_400.php などの名前が付いています。

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <title>Error</title> 
</head> 
<body> 
<div id="container"> 
    <h1><?php echo $heading; ?></h1> 
    <?php echo $message; ?> 
</div> 
</body> 
</html> 

(ただし、error_general.phpをコピーして必要に応じて変更できます)。
次に、あなたの上書きURIクラスでは、あなたが(代わりにリダイレクトの)このようなカスタムページを表示することができます。

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

class MY_URI extends CI_URI { 
    /** 
    * Filter segments for malicious characters 
    * 
    * @access private 
    * @param string 
    * @return string 
    */ 
    function _filter_uri($str) 
    { 
     if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE) 
     { 
      // preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards 
      // compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern 
      if (! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", $str)) 
      { 
       $_error =& load_class('Exceptions', 'core'); 
       echo $_error->show_error('The URI you submitted has disallowed characters.', 'The URI you submitted has disallowed characters.', 'error_400', 400); 
       exit; 
      } 
     } 

     // Convert programatic characters to entities 
     $bad = array('$',  '(',  ')',  '%28',  '%29'); 
     $good = array('&#36;', '&#40;', '&#41;', '&#40;', '&#41;'); 

     return str_replace($bad, $good, $str); 
    } 
} 

のTh

+0

今エラーがMY_URIファイルにアクセスすることができないため、それは常にからのメッセージをロードしますシステム/コアのURI.php –

+0

今はMY_URIが読み込まれていないのですが、MY_URIで編集したものとしてエラーメッセージが表示されず、編集する必要のあるエラーページがフォルダ内にあります。** view/error/html ** –

関連する問題