Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.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
Phoenix framework 链接到资源的slug_Phoenix Framework - Fatal编程技术网

Phoenix framework 链接到资源的slug

Phoenix framework 链接到资源的slug,phoenix-framework,Phoenix Framework,我有一个国家: mix phx.gen.html Location Country countries name slug:unique 要链接到国家/地区,我想使用slug,而不是id。如何实现此代码链接到slug(例如http://localhost:4000/countries/germany) 您需要实现模块的协议。最简单的方法是在模块中的模式“…”之前添加以下内容: @derive {Phoenix.Param, key: :slug} schema "..." do ...

我有一个
国家

mix phx.gen.html Location Country countries name slug:unique
要链接到
国家/地区
,我想使用
slug
,而不是
id
。如何实现此代码链接到
slug
(例如
http://localhost:4000/countries/germany


您需要实现模块的协议。最简单的方法是在模块中的
模式“…”
之前添加以下内容:

@derive {Phoenix.Param, key: :slug}
schema "..." do
  ...
end

现在,当从Phoenix生成的URL帮助程序生成链接时,将使用
slug
字段而不是
id

您是否尝试在
国家/地区路径中使用
country.slug
@derive {Phoenix.Param, key: :slug}
schema "..." do
  ...
end