我使用的是 SF 1.3.6。我有一些静态文本文件 (HTML),我希望能够在弹出窗口中显示它们。
我尝试过这个:
<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。我该如何解决这个问题?
注意:我真的不想为这些静态文件编写路由、操作和模板 - 还有其他方法可以使用 SF 实现弹出窗口吗?
[编辑]
这是我原来的 .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 | Not Found | sfError404Exception Empty module and/or action after parsing the URL "/foobar.html" (/).
最佳答案
默认的 Symfony .htaccess 文件应该有一行来提供 Web 目录中已存在的文件。确保您为文件指定的路径存在于 web.xml 中。以下是 .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>
关于php - Symfony 1.3.6 - javascript 弹出窗口 - 如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4195537/