2013-12-18 43 views
1

我試着使菜單中的MVC結構.. 的問題是,我有網站的子目錄,在我的網站根目錄,如:PHP路徑

本地主機/子目錄/

但是當我點擊我的鏈接它回到我的根。菜單被稱爲一個模型(在momment靜態),在一個關聯數組,其中關鍵是鏈接名稱,和值是路徑名,例如:

$this->viewModel->set("mainMenu",array("Forside" => "/home", "Hjælp" => "/help")); 

我在通話中時它視圖文件:

 foreach ($viewModel->get('mainMenu') as $key => $values){ 
       echo '<a href="'. $values. '">' . $key . '</a> '; 
     } 

我的.htaccess文件:

Options +FollowSymLinks 
RewriteEngine on 



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

我試圖讓我用一個反斜槓環節,即這麼想的工作.. 我試圖讓沒有鏈接斜線,工作als ong,因爲我在localhost/subdir/home,但是當我去localhost/subdir/home/view, 並點擊home鏈接,它只是去localhost/subdir/home/home

我已經試過定義一個BASE_ROOT,不工作。 ,並與形成我DIRECTORY_SEPARATOR不工作:(

對不起我的英語不好一樣,我真的希望有人能幫助我在這裏

+0

什麼是'index.php'和的.htaccess的位置?他們在'/ subdir /'或根目錄下? – anubhava

+0

他們在子目錄 – Cruelcrome

+0

好的在下面提供了一個答案。 – anubhava

回答

2

保持你的鏈接絕對即以斜線起:/home/help

添加這條規則在您的/DocumentRoot/.htaccess

Options +FollowSymLinks 
RewriteEngine on 

RewriteRule !^subdir /subdir/%{REQUEST_URI} [L,NC,R] 

[R請記得這正好在subdir

+0

好吧,它的工作有點,現在然後我點擊鏈接它仍然發送給我的根,但我可以看到的意見..我可能會幫助,如果你可以看看該項目..你可以下載它在:https: //github.com/ndavison/Nathan-MVC ..其在/classes/basemodel.php下和/views/maintemplate.php和ofc htacces在根:) – Cruelcrome

+0

我會嘗試,一旦我回到我的電腦。同時我編輯了我的答案,你現在可以試試嗎? – anubhava

+0

史詩它的工作非常感謝:),我一直在努力與此 – Cruelcrome

0

父目錄試試這個

RewriteEngine on 

RewriteRule ^(.*)$ /ocalhost/subdir/$1 [L]