Phalcon 继续为不同的 Controller 使用index.phtml

标签 phalcon

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

我一直在遵循教程并遇到问题。当我使用链接加载其他 Controller 时,地址栏显示正确的路径,但据我所知,每次都会加载index.phtml。我上传了文件here所以你可以亲自看看。

我是否使用 Tag::LinkTo() 并不重要,因为它不会改变。

编辑:

我关注了instructions ,从/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 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6f0e0b0206012f0a170e021f030a4107001c1b" rel="noreferrer noopener nofollow">[email protected]</a>
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 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a0c1c4cdc9cee0c5d8c1cdd0ccc58ec8cfd3d4" rel="noreferrer noopener nofollow">[email protected]</a>
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。

最佳答案

您的 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 传递到您的浏览器

关于Phalcon 继续为不同的 Controller 使用index.phtml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13453880/

相关文章:

php - Phalcon在模型中执行sql查询

php - PhalconPHP 动态创建表

http-headers - 无法获取标题 AUTHORIZATION 但更改为 AUTHORIZATION 可以获得值

model-view-controller - Phalcon:如何获取 Controller 和操作名称

php - 错误构建 : fatal error: pcre. h:没有这样的文件或目录

post - 带有 JavaScript 确认对话框的 Phalcon PHP 发布链接

phalcon - 如何在 Controller 、模型或 View 之外的文件中引用 session 变量?

Phalconphp micro mvc路由问题

php - 在 Phalcon 2 中找不到类用户

jquery - 如何从 phalcon 的数据库中检索相似的标签数据?