何时更改CakePHP中路由的基本路径? [英] Ho do I change the base path of routes in CakePHP?

查看:151
本文介绍了何时更改CakePHP中路由的基本路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CakePHP来制作一个Facebook应用程序(虽然问题不是Facebook的具体)。像往常一样,我正在努力使反向路由工作正常。以前我已经放弃了路由功能,但这次我真的很想让它工作。

I'm using CakePHP to produce a Facebook application (though the problem is not Facebook specific). As usual, I'm struggling to get the reverse routing to work properly. Previously I've abandoned the routing functionality, but this time I'd really like to make it work.

问题基本上是Cake生成相对于主机服务器,但我们需要相对于Facebook画布页面的URL。所以,当我输入:

The problem is basically that Cake produces URLs relative to the base of the host server, but we need URLs relative to the Facebook canvas page. So, when I type:

echo $html->link(__('New Question', true), array('action'=>'add'));

我希望它生成 http://apps.facebook.com/appname/admin/questions/add ,而是生成 http://apps.facebook.com/ foo / bar / appname / admin / questions / add,其中foo / bar是从我的主机根目录到应用程序目录的路径。

I want it to produce "http://apps.facebook.com/appname/admin/questions/add", but it instead produces http://apps.facebook.com/foo/bar/appname/admin/questions/add", where foo/bar is the path from my host root to the app directory.

在配置文件夹中附带的文件,我没有看到任何明显的任何指针?

Having poked around the files in the config folder, I didn't see anything obvious. Any pointers?

推荐答案

图解出来。

只需添加一个行:

Configure::write('App.base', '/appname/');

我把它放在我的应用程序的bootstrap.php中,但我不认为这太重要了,甚至可以回去添加几行来检测是否在本机或通过Facebook运行...

I put it in my app's bootstrap.php, but I don't think it matters too much. I might even go back and add a few lines to detect whether it's running natively or through Facebook...

这篇关于何时更改CakePHP中路由的基本路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆