You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Statamic 3.3升级至4.5后子条目URL路径合并异常求助

解决Statamic 4.5中子条目URL层级路径失效问题

1. 检查集合路由配置

  • 进入后台集合设置(Collections -> 目标集合 -> Settings),确认Route模板设置为包含父条目slug的格式,比如 {{ parent:slug }}/{{ slug }},而非仅{{ slug }}。
  • 若通过配置文件管理集合(config/statamic/collections.php),对应集合添加或修改route字段:
    'route' => '{{ parent:slug }}/{{ slug }}',
    

2. 强制Eloquent Driver生成层级URI

由于使用Eloquent Driver,需确保条目保存时生成完整层级路径,可通过事件监听实现:

  • 在App\Providers\EventServiceProvider中注册事件监听:
    protected $listen = [
        \Statamic\Events\EntrySaving::class => [
            \App\Listeners\GenerateHierarchicalUri::class,
        ],
    ];
    
  • 创建监听类App\Listeners\GenerateHierarchicalUri:
    <?php
    
    namespace App\Listeners;
    
    use Statamic\Events\EntrySaving;
    
    class GenerateHierarchicalUri
    {
        public function handle(EntrySaving $event)
        {
            $entry = $event->entry;
            if ($parent = $entry->parent()) {
                $entry->setUri(rtrim($parent->uri(), '/') . '/' . $entry->slug());
            }
        }
    }
    

3. 修复已有条目并刷新缓存

  • 直接在数据库中更新子条目uri字段为完整路径(如/home/test)。
  • 执行命令刷新路由缓存:
    php artisan statamic:clear:routes
    php artisan route:cache
    

4. 禁用自动扁平化URI设置

  • 检查集合设置中的URI Generation选项,确保未勾选“Flatten URI”相关选项。
  • 配置文件中对应集合设置flat为false:
    'flat' => false,
    

内容的提问来源于stack exchange,提问作者Matthew Bradley

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 07:16:02