2010-11-16 32 views
0

我正在使用SF 1.3.6。我有一些靜態文本文件(HTML),我希望能夠在彈出窗口中顯示。Symfony 1.3.6 - javascript popup windw - 如何?

我嘗試這樣做:

<a href="javascript:showPopup('foobar.html', 'all about foobar')">foobar</a><br /> 

<script type="text/javascript"> 
function showPopup(url, title) { window.open(url,title,"menubar=no,width=430,height=360,toolbar=no");} 
</script> 

我得到一個sf404Exception當我點擊的鏈接。我該如何解決這個問題?

注意:我真的不想爲這些靜態文件編寫路由,動作和模板 - 是否有另一種方式來實現彈出窗口?

[編輯]

這是我原來的.htaccess的內容。

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    #force everything to www so URLs look the same 
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC] 
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] 

    # uncomment the following line, if you are having trouble 
    # getting no_script_name to work 
    #RewriteBase/

    # we skip all files with .something 
    #RewriteCond %{REQUEST_URI} \..+$ 
    #RewriteCond %{REQUEST_URI} !\.html$ 
    #RewriteRule .* - [L] 

    #redirect on trailing slash (otherwise, Symfony will 404) 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)/$ /$1 [R=302,L] 

    # we check if the .html version is here (caching) 
    RewriteRule ^$ index.html [QSA] 
    RewriteRule ^([^.]+)$ $1.html [QSA] 
    RewriteCond %{REQUEST_FILENAME} !-f 

    # no, so we redirect to our front web controller 
    RewriteRule ^(.*)$ index.php [QSA,L] 
</IfModule> 

我用Jeremy的腳本取而代之。然後我重新啓動Apache,但我得到相同的錯誤

404 |未找到| sfError404Exception 解析URL「/foobar.html」(/)後的空模塊和/或動作 。

+0

在web文件夾的頂層是foobar.html嗎? – 2010-11-16 21:40:51

+0

是的文件位置是這樣的:web/foobar.html – skyeagle 2010-11-16 23:07:26

回答

1

默認的Symfony .htaccess文件應該有一行來提供web目錄中已存在的文件。確保您爲文件指定的路徑存在於Web內部。下面是從.htaccess中的相關線路:

# we check if the .html version is here (caching) 
RewriteRule ^$ index.html [QSA] 
RewriteRule ^([^.]+)$ $1.html [QSA] 
RewriteCond %{REQUEST_FILENAME} !-f 

這裏是我的完整的.htaccess與其他一些改進:

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    #force everything to www so URLs look the same 
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC] 
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] 

    # uncomment the following line, if you are having trouble 
    # getting no_script_name to work 
    #RewriteBase/

    # we skip all files with .something 
    #RewriteCond %{REQUEST_URI} \..+$ 
    #RewriteCond %{REQUEST_URI} !\.html$ 
    #RewriteRule .* - [L] 

    #redirect on trailing slash (otherwise, Symfony will 404) 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)/$ /$1 [R=302,L] 

    # we check if the .html version is here (caching) 
    RewriteRule ^$ index.html [QSA] 
    RewriteRule ^([^.]+)$ $1.html [QSA] 
    RewriteCond %{REQUEST_FILENAME} !-f 

    # no, so we redirect to our front web controller 
    RewriteRule ^(.*)$ index.php [QSA,L] 
</IfModule> 
+0

嗨傑里米,請參閱我編輯的問題。謝謝 – skyeagle 2010-11-16 16:31:59

0

你在哪裏存儲靜態文件嗎?要通過/foobar.html訪問它們,您需要將其放在web/目錄中。

此外,請記住讓它們可以由Web服務器讀取。

+0

嗨庫巴:我的文件在web文件夾中,它們可以被所有人讀取(模式:644) – skyeagle 2010-11-16 22:20:36

+0

我不會說這是一個symfony問題,也不是.htaccess問題。我只用一個默認的.htaccess對vanilla symfony項目進行了測試,它只是起作用(許可644)。你有沒有將你的主機配置爲symfony文檔中的建議? – 2010-11-16 23:15:38

1

嘗試添加一個前導「/」到foobar.html。

javascript:showPopup('/foobar.html', 'all about foobar') 

如果您在開發環境的時候,然後調用foobar.html實際上將調用frontend_dev.php/foobar.html。將前導「/」條添加到frontend_dev.php中。