我可以在CakePHP中更改路由的基本路径吗? [英] Ho do I change the base path of routes in CakePHP?

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

问题描述

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



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

  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是从我的主机根目录到应用程序目录的路径。



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

解决方案

b
$ b

只需添加以下行:

 配置:: write ','/ appname /'); 

我把它放在我的应用程序的bootstrap.php,不要认为它太重要了,我甚至可以回去,添加几行,以检测它是运行本机还是通过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.

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'));

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?

解决方案

Figure it out.

Just needed to add this line:

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

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天全站免登陆