【问题标题】:Phalcon\Tag::linkTo URL not containing the subfolder where the project livesPhalcon\Tag::linkTo URL 不包含项目所在的子文件夹
【发布时间】:2012-09-21 15:25:04
【问题描述】:

我正在使用 PHP 5.3、phalcon 0.5.0 在 OS X 10.8 上关注 tutorial。我的 apache 的 Web 根目录中有一个名为 tutorial 的文件夹。当我使用代码时:

echo Phalcon\Tag::linkTo("signup", "Sign Up Here!");

在我得到的输出 html 中

localhost/signup 

而不是

localhost/tutorial/signup

我还在 .htacess 文件中输入了 RewriteBase /tutorial/,但仍然遇到同样的问题。我在 phalcon 的 0.4 和 0.5 中也遇到了同样的问题

【问题讨论】:

    标签: php rewrite phalcon


    【解决方案1】:

    URL 重写需要在引导期间在项目的 DI 容器中注册(文件 public/index.php)

    // Setting up the view component
    $di->set(
        'url', 
        function() {
            $url = new \Phalcon\Mvc\Url();
            $url->setBaseUri('/tutorial/');
            return $url;
        }
    );
    

    这将有效地指示 Phalcon 在内部使用子文件夹以及 \Phalcon\Tag::linkTo() 函数。请注意 setBaseUri() 中的结尾斜线“/”字符

    【讨论】:

    猜你喜欢
    • 2014-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-17
    • 2010-10-19
    • 2011-12-29
    • 2014-01-03
    • 1970-01-01
    相关资源
    最近更新 更多