2

私は自分で作った PHP CMS を使用しています。$_GET パラメータurlをフェッチし、それを に変換しwww.website.com/{url}ます。この CMS は、$_GET パラメータを使用してファイルを取得します。したがって、 が の場合、urlCMSindexはファイルを検索し、ファイルindexの内容を返します。しかし今、私は CMS を拡張して、 のような追加パラメータを持たせていますprofile/{username}。どうすればそれを拡張できますか?URL にwww.website.com/profile/{username}. どうすればこれを行うことができますか?これは私の現在のhtaccessです:

RewriteEngine On  
RewriteRule ^(|/)$ index.php?url=$1  
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ index.php?url=$1a

これがTPLシステムです。

public function addTpl() {     
    global $zip;

    if(!isset($_GET['url']) || empty($_GET['url'])) {
        $_GET['url'] = 'index';
    }

    if(file_exists('_zip/_templates/_front/'. $zip['Template']['Front'] . '/')) {
        if(file_exists('_zip/_templates/_front/'. $zip['Template']['Front'] . '/' . secure($_GET['url']) . '.php')) {
            ob_start();
            include('_zip/_templates/_front/'. $zip['Template']['Front'] . '/' . secure($_GET['url']) . '.php');
            $this->tpl .= ob_get_contents();
            ob_end_clean();
        } else {
            die(zipError('File Not Found', 'The file <b>' . secure($_GET['url']) . '</b> could not be found. Please re-check the URL; If you were directed here using a link, please report that link.'));
        }
    } else {
        die(zipError('Template Not Found', 'The template <b>' . $zip['Template']['Front'] . '</b> could not be found. Please check your configuration file for a mistake.'));
    }
}

他に提供する必要がある情報はありますか? 私はこれをできるだけ早く終わらせる必要があるので、アドバイスをいただければ幸いです。

4

2 に答える 2

4

ファイルをインクルードする前に、2 番目のパラメーター ( {username} ) をローカル変数にすることができます。これにより、通常の変数としてアクセスできます。チームで作業している場合、これは良いことではありません。

編集

あなたができることは次のとおりです

RewriteEngine On  
RewriteRule ^ index.php

次に、index.phpでこれを使用できます

$url = str_replace('index.php','', $_SERVER['PHP_SELF']);
$url = str_replace($url,'',$_SERVER['REQUEST_URI']);
$url = explode('/',$url);
$page = array_shift($url);
foreach ($url as $val){
    $args[] = urldecode($val);
}

リンクを開くwww.website.com/profile/someuser/aboutと 、

$page = 'profile'
$args[0] = 'someuser'
$args[1] = 'about'

などなど、好きなだけ議論をすることができます。

于 2013-06-10T00:05:01.120 に答える