2017-06-04 18 views
1

我做了一個引導類,它保存重定向並從URL獲取參數。在Bootstrapping中的查詢

class Bootstrap 
{ 
    private $controller; 
    private $action; 
    private $request; 

    public function __construct($request){ 
     $this->request = $request; 
     if ($this->request['controller'] == '') { 
      $this->controller = 'home'; 
     } else { 
      $this->controller = $this->request['controller']; 
     } 

     if ($this->request['action'] == '') { 
      $this->action = 'index'; 
     } else { 
      $this->action = $this->request['action']; 
     } 
     echo $this->controller; 
    } 
} 

我已經將我的域從localhost更改爲php.dev。現在的問題是,只要我在url中輸入一些東西,它只回應「索引」或動作,甚至我在動作中放入了一些東西,它仍然回顯「索引」。例如:我輸入了php.dev/users/,它應該回顯單詞「用戶」控制器。這是我的.htaccess文件:

Options +FollowSymLinks 
RewriteEngine on 
RewriteRule ^([a-zA-Z)]*)/?([a-zA-Z]*)?/?([a-zA-z)-9]*)?/?$ index.php?controller=$1&action=$2&id=$3 [NC,L] 

回答

1

試試這個規則:

RewriteRule ^([^/]+)(/([^/]+)(/([^/]+))?)?/?$ index.php?controller=$1&action=$3&id=$5 [NC,QSA,L] 

我用它在我的項目,它的作品,因爲它應該。如果問題仍然存在,請確保在將請求傳遞給課程時正確填寫$ request。

+0

它工作!感謝您的幫助伴侶。非常感謝。 –

+0

對不起,我剛纔意識到,當我進入php.dev只有它回聲index.php不在家? –

+0

嘗試在規則之前添加以下行: 'RewriteCond%{REQUEST_FILENAME}!-d'和'RewriteCond%{REQUEST_FILENAME}!-f' – Anton