-1

我在正确显示我的网站的 URL 时遇到问题。我正在使用最新版本的 Codeigniter。

我收到以下错误消息。我正在做一些研究,我认为我的问题是 URI 段,但我对如何解决问题感到困惑。

我的目标是让 URL 看起来不错(_states 是我的本地主机上的子目录文件夹) mydomain.com/_states/dealers/Florida (这个 URL 实际上有效) mydomain.com/_states/dealers/Florida/Miami (不是工作)mydomain.com/_states/dealers/Florida/Miami/8(不工作)

我还为我的 routes.php 和 model_data.php 提供了语法。你们将如何解决这个问题?提前感谢大家。

A PHP Error was encountered

Severity: Warning

Message: Missing argument 2 for Site::getDealersCity()

Filename: controllers/site.php

Line Number: 43

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: city

Filename: controllers/site.php

Line Number: 47

现场控制器

   public function getDealersCity($state, $city){
     //$city = $this->uri->segment(3);
     //echo "$city";
     if(is_null($state)) return false;
     if(is_null($city)) return false;
     $this->load->model('model_data');
     $data['statecity'] = $this->model_data->get_database_by_cities($state,$city);
     $this->load->view('statecity',$data);
   }

模型数据.php 函数

function get_database_by_cities($state, $city){
    $query = $this->db->get_where('states',
    array('state' => $state,
    'city' => $city)
    );
    if($query->num_rows()) return $query->result();
    return null;
}

路由.php

$route['default_controller'] = "site";
$route['dealers/(:any)/(:any)'] = "site/getUniqueDealerInfo/$3";
$route['dealers/(:any)/(:any)'] = "site/getDealersCity/$2";
$route['dealers/(:any)'] = "site/getCities/$1";
$route['404_override'] = '';
4

1 回答 1

2
$route['dealers/(:any)/(:any)'] = "site/getUniqueDealerInfo/$3";
$route['dealers/(:any)/(:any)'] = "site/getDealersCity/$2";

路线本质上是冲突的,一条路线优先于另一条路线。

尝试使用

$route['dealers/(:any)/(:any)'] = "site/getDealersCity/$1/$2";

并且没有功能

获取唯一经销商信息

看看这里的答案类似的问题

于 2013-06-04T18:10:24.520 回答