【问题标题】:How to make a function to geojson in codeigniter 4如何在codeigniter 4中为geojson创建一个函数
【发布时间】:2020-08-16 07:11:36
【问题描述】:

这是Codeigniter 3中的示例函数:

public function geoJSON()
{
    $records = $this->example_model->getAll();
    $this->load->view('geojson', ['records'=>$records]);        
}

...但它在 Codeigniter 4 中不起作用。为什么?

【问题讨论】:

  • 欢迎堆栈溢出!不幸的是,这个问题不够详细,无法为您提供任何有意义的帮助。请编辑您的问题,为该问题添加 minimal reproducible example
  • 什么是geojson?也许您的意思是地理坐标为 json?
  • 我在表中有 mysql 数据,如坐标和其他属性,我将使用 php 将其设置为 geojson,然后使用 javascript 将 geojson 显示到地图上,在 ci3 中它可以工作,但在 ci4 它没有不工作,怎么样..

标签: json codeigniter geojson codeigniter-4


【解决方案1】:

因为 Codeigniter 4 使用 PHP 7.0 ++,而在 PHP 5.4 之前支持上述语法 我想你需要这样的东西

$records = $this->Model->getAll();
             $this->load->view('geojson', $data['records'] = $records);

甚至更好

$data['records'] = $this->Model->getAll();
                 $this->load->view('geojson', $data);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-14
    • 1970-01-01
    • 1970-01-01
    • 2020-05-14
    • 1970-01-01
    相关资源
    最近更新 更多