Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.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
Php 调用未定义的方法Spatie\Sitemap\Sitemap::getType()_Php_Laravel_Sitemap_Spatie - Fatal编程技术网

Php 调用未定义的方法Spatie\Sitemap\Sitemap::getType()

Php 调用未定义的方法Spatie\Sitemap\Sitemap::getType(),php,laravel,sitemap,spatie,Php,Laravel,Sitemap,Spatie,我正在尝试为网站地图的所有项目编制索引。我正在使用该软件包来完成此操作。目前,我们有超过65000个项目,这是有问题的,因为一个网站地图只能包含50000个链接。不管怎样,这个包有一个解决方案:一个指向多个站点地图的站点地图索引。由于这些项目无法从网站上的任何其他页面访问,我不能只使用爬行功能,我必须手动添加链接。这就是我下面要做的。然而,我有两个问题: 我有一半的时间都会犯错误 我在尝试将站点地图写入文件时遇到此错误: 我不确定为什么会出现这个错误,也不知道如何确保在执行此代码时有一个要获取的

我正在尝试为网站地图的所有项目编制索引。我正在使用该软件包来完成此操作。目前,我们有超过65000个项目,这是有问题的,因为一个网站地图只能包含50000个链接。不管怎样,这个包有一个解决方案:一个指向多个站点地图的站点地图索引。由于这些项目无法从网站上的任何其他页面访问,我不能只使用爬行功能,我必须手动添加链接。这就是我下面要做的。然而,我有两个问题:

  • 我有一半的时间都会犯错误
  • 我在尝试将站点地图写入文件时遇到此错误:
  • 我不确定为什么会出现这个错误,也不知道如何确保在执行此代码时有一个要获取的类型。。。但我知道问题代码是:

    
    @foreach($tags作为$tag)
    @包括('laravel-sitemap::sitemapIndex/'。$tag->getType())
    @endforeach
    
    这是我的密码:

            $this->info('Generate Sitemap');
            $this->info(config('app.url'));
    
            $sitemapPath = public_path('sitemap.xml');
            $siteMapIndex = SitemapIndex::create();
    
            $page = 1;
            $size = 1000;
            $max_result_window = 10000;
            $data = json_decode('{"sort":"updated_at","order":"DESC","page":'.$page.',"size":'.$size.',"active":1,"search_criteria":[{"field":"active","value":1,"operator":"eq","nested":false}], "source": "sitemap"}', true);
    
            // Get first result
            $response = $this->itemService->getByCriteria($data);
    
            try {
                $total_results = 0;
    
                $this->info("Max result window: " . $max_result_window);
    
                for ($i = 0; $i < 6; $i++)
                // TODO: get total number of items for this loop
                {
                    $sitemap = Sitemap::create(config('app.url'));
    
                    $this->info("Indexing items " . ($i*$max_result_window+1) . " to " . ($i+1)*$max_result_window);
                    while ($total_results < ($max_result_window - $size))
                        // While we have less than the maximum number of results allowed by elastic...
                    {
                        foreach ($response->hits->hits as $item) // Add a link for each item to the sitemap
                        {
                            $sitemap->add(Url::create("/shop/" . $item->_id));
                        }
    
                        // Some stats
    
                        $total_results = ($page * $size - ($size - sizeof($response->hits->hits)));
    
                        $this->info("Items indexed: " . ($max_result_window * $i + $total_results));
    
                        //Get next page
                        $page++;
                        $data = json_decode('{"sort":"updated_at","order":"DESC","from":' . ($i*$max_result_window) . ',"page":' . $page . ',"size":' . $size . ',"active":1,"search_criteria":[{"field":"active","value":1,"operator":"eq","nested":false}], "source": "sitemap"}', true);
                        $response = $this->itemService->getByCriteria($data);
                    }
                    //Reset. We are moving the result window.
                    $page = 1;
                    $total_results = 0;
    
                    // Write sitemap to sitemap index and move on to create a new index.
                    $siteMapIndex->add($sitemap);
                    $sitemap = null;
                    unset($sitemap);
                }
            } catch (\Exception $e) {
                var_dump($response);
            }
    
            $siteMapIndex->writeToFile($sitemapPath);
    
    $this->info('Generate Sitemap');
    $this->info(配置('app.url');
    $sitemapPath=public_path('sitemap.xml');
    $siteMapIndex=siteMapIndex::create();
    $page=1;
    $size=1000;
    $max_result_window=10000;
    $data=json_decode(“{”排序“:”更新的_at“,”顺序“:”描述“,”页面“:”,”大小“:”$size.”,“活动“:”1,“搜索条件“:[{”字段“:”活动“,”值“:”1,“运算符“:”eq“,”嵌套“:”假“,”源“:”站点地图“}”,真);
    //初见成效
    $response=$this->itemService->getByCriteria($data);
    试一试{
    $total_results=0;
    $this->info(“最大结果窗口:”.$Max\u结果窗口);
    对于($i=0;$i<6;$i++)
    //TODO:获取此循环的项目总数
    {
    $sitemap=sitemap::create(配置('app.url');
    $this->info(“索引项”。($i*$max\u result\u window+1)。“到”。($i+1)*$max\u result\u window);
    而($total_results<($max_result_window-$size))
    //虽然我们得到的结果少于弹性体所允许的最大数量。。。
    {
    foreach($response->hits->hits as$item)//为站点地图中的每个项目添加链接
    {
    $sitemap->add(Url::create(“/shop/”$item->_id));
    }
    //一些统计数据
    $total_results=($page*$size-($size-sizeof($response->hits->hits));
    $this->info(“索引项:”($max\u result\u window*$i+$total\u results));
    //获取下一页
    $page++;
    $data=json_解码(“{”排序“:”更新_at“,”顺序“:”DESC“,”from“:”($i*$max_结果_窗口)”,“页面“:”,”页面“,”页面“,”大小“,”大小“,”大小“,”活动“,”搜索条件“:[{”字段“:”活动“,”值“:”1,“运算符“:”eq“,”嵌套“:”假“,”源“:”站点地图“}”,真);
    $response=$this->itemService->getByCriteria($data);
    }
    //重置。我们正在移动结果窗口。
    $page=1;
    $total_results=0;
    //将站点地图写入站点地图索引,然后继续创建新索引。
    $siteMapIndex->add($sitemap);
    $sitemap=null;
    unset($网站地图);
    }
    }捕获(\异常$e){
    var_dump($response);
    }
    $siteMapIndex->writeToFile($sitemapPath);
    
    好的,所以我出现这个错误的原因是因为我试图将一个站点地图对象添加到索引中。我应该这样加上:

    $sitemap->writeToFile($sitemapPath);
    $siteMapIndex->add($sitemapPath);
    
    本文档提供了一个添加站点地图对象的示例,但这仅适用于更改
    lastModificationDate
    的情况,如本文档中的以下示例所示:

    SitemapIndex::create()
        ->add('/pages_sitemap.xml')
        ->add(Sitemap::create('/posts_sitemap.xml')
            ->setLastModificationDate(Carbon::yesterday()))
        ->writeToFile($sitemapIndexPath);
    
    因此,正确的实施方式是:

  • 创建站点地图
  • 添加链接
  • 编写站点地图
  • 按路径将站点地图添加到站点地图索引
  • $sitemap->writeToFile($sitemapPath);
    $siteMapIndex->add($sitemapPath);
    
    SitemapIndex::create()
        ->add('/pages_sitemap.xml')
        ->add(Sitemap::create('/posts_sitemap.xml')
            ->setLastModificationDate(Carbon::yesterday()))
        ->writeToFile($sitemapIndexPath);