2

我是 Phalcon 的新手,我喜欢这个框架,但我的链接有问题。我使用 phalcon 0.6.1 版和 XAMPP 1.8.1 将 vhosts 设置为我 phalcon 测试所在的 xampp/htdocs/test。

我一直在关注教程并遇到了一个问题。当我使用链接加载其他控制器时,地址栏会显示正确的路径,但据我所知,每次都会加载 index.phtml。我把文件上传到这里,你可以自己看看。

如果我使用 Tag::LinkTo() 或者因为它没有改变,这并不重要。

编辑:

我按照说明,从 /test 和 /test/public 目录中删除了 .htaccess 文件,将其移至 httpd.conf。最后我添加了

<Directory "C:/xampp/htdocs/www/test">
    RewriteEngine on
    RewriteRule  ^$ public/    [L]
    RewriteRule  (.*) public/$1 [L]
</Directory>

<Directory "C:/xampp/htdocs/www/test/public">
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</Directory>

并像这样修改了我的 httpd-vhosts.conf

ServerAdmin admin@example.host
DocumentRoot "C:/xampp/htdocs/test/public"
DirectoryIndex index.php
ServerName example.host
ServerAlias www.example.host

<Directory "C:/xampp/htdocs/test/public">
    Options All
    AllowOverride All
    Allow from all
</Directory>

页面加载,但像 /public/css/bootstrap.min.css 这样的绝对链接不起作用,当我单击该链接时,它给我一个错误 404 并说找不到对象。我修改了这样的文件:

<Directory "C:/xampp/htdocs/test">
    RewriteEngine on
    RewriteRule  ^$ public/    [L]
    RewriteRule  (.*) public/$1 [L]
</Directory>

<Directory "C:/xampp/htdocs/test/public">
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</Directory>

ServerAdmin admin@example.host
DocumentRoot "C:/xampp/htdocs/test"
DirectoryIndex index.php
ServerName example.host
ServerAlias www.example.host

<Directory "C:/xampp/htdocs/test">
    Options All
    AllowOverride All
    Allow from all
</Directory>

但这给我带来了最初的问题,即当我单击链接时,它会再次加载 index.phtml,即使它在 URL 中显示 localhost:8005/sample 也是如此。

4

1 回答 1

2

看起来您的 Apache 配置不允许读取 .htaccess 文件:

<VirtualHost *:80>

    ServerAdmin admin@localhost
    ServerName phalcon.test

    DocumentRoot /srv/htdocs/sites/test        

    <Directory "/srv/htdocs/sites/test">
        AllowOverride All
        Options All
        Order allow,deny
        Allow from all
    </Directory>

</VirtualHost>

此外,在您的 public/index.php 顶部检查 $_GET['_url'] 是否已将 URI 传递给您的浏览器

于 2012-11-19T18:22:04.523 回答