在Bootstrapping中查询

时间:2017-06-04 01:27:08

标签: php .htaccess

我创建了一个bootstrap类,它保存重定向并从URL获取参数。

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 个答案:

答案 0 :(得分:1)

尝试此规则:

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

我在我的项目中使用它,它可以正常工作。如果问题仍然存在,请确保在将请求传递给类时正确填写$。

相关问题