2016-10-07 7 views
-4
public function processApi(){  
    $func = strtolower(trim(str_replace("/","",$_SERVER['REQUEST_URI'])));  //echo $func; 

    if((int)method_exists($this,$func) > 0)   
    $this->$func();  
    else    
    $this->response('',404); 

    echo '404';  // If the method not exist with in this class, response would be "Page not found". 
} 

答えて

0

あなたは、このメソッドに

public function processApi(){  
     $func = strtolower(trim(str_replace("/","",$_SERVER['REQUEST_URI'])));  
     if(method_exists(get_called_class(), $func)) 
      { 
       $this->$func(); 
      }else{ 
       $this->response('method not exists',404); 
      } 
    } 

クラス名を取得


get_called_class()

このコードを使用する必要がありますメソッドの戻り値で

セットのクラス名が真の偽の方法が存在するか

method_exists(get_called_class()、$ funcを)

は、このコードに返信用

+0

感謝をしてみてください。 、それでもエラーです。 エラー:予期しない '' – jerry

+0

MVC構造体を使用するとエラーが発生しますが、コアoopsを使用すると何も得られませんMVCを使用する場合はエラーが発生します$ this-> router-> fetch_method(); $ _SERVER ['REQUEST_URI']を置き換えます –

+0

私はコアコードを使用しました。 – jerry