Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Symfony2上使用Hateoas捆绑包获得绝对url_Symfony_Hateoas - Fatal编程技术网

如何在Symfony2上使用Hateoas捆绑包获得绝对url

如何在Symfony2上使用Hateoas捆绑包获得绝对url,symfony,hateoas,Symfony,Hateoas,我刚从Willdurant的github新安装了捆绑包,得到的相对url如下: "_links": { "self": { "href": "/1.0/users/?page=1&limit=10" }, "first": { "href": "/1.0/users/?page=1&limit=10" }, "last": { "href": "/1.0/users/?page=2&limit=1

我刚从Willdurant的github新安装了捆绑包,得到的相对url如下:

"_links": {
    "self": {
      "href": "/1.0/users/?page=1&limit=10"
    },
    "first": {
      "href": "/1.0/users/?page=1&limit=10"
    },
    "last": {
      "href": "/1.0/users/?page=2&limit=10"
    },
    "next": {
      "href": "/1.0/users/?page=2&limit=10"
    }
  }
对于我的Hateoas url,我真的更喜欢绝对url,但我在谷歌上找不到任何东西可以改变这一点。2小时的搜索,尝试多个关键字,什么都没有


谢谢你的帮助。

你可以用很多方法。这一切都取决于生成链接的方式

如果您使用
@Route
注释来生成链接,它有一个参数
absolute
,需要设置为
true

/**
 * @Hateoas\Relation(
 *     name = "self",
 *     href = @Hateoas\Route(
 *         "user_get",
 *         parameters = { "id" = "expr(object.getId())" },
 *         absolute = true
 *     )
 * )
 */
如果使用表达式语言生成链接,则可以将
true
作为第三个参数传递给
link()
函数:

/**
 * @Hateoas\Relation(
 *     "user",
 *     href = "expr(link(object.getUser(), 'self', true))"
 * )
 */

发布生成此输出的代码。您在我的帖子中看到的链接是由用于分页的捆绑包自动生成的,这就是为什么我不知道如何在不更改供应商代码的情况下更改这些链接。否则,对于关系,你是对的,谢谢你的样品!