我的网站正确显示网址时出现问题。我正在使用最新版本的Codeigniter。
我收到以下错误消息。我正在做一些研究,我认为我的问题是URI段,但我很困惑如何解决问题。
我的目标是让网址看起来不错 (_states是我localhost上的子目录文件夹) 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);
}
Model_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;
}
routes.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'] = '';
答案 0 :(得分:2)
$route['dealers/(:any)/(:any)'] = "site/getUniqueDealerInfo/$3";
$route['dealers/(:any)/(:any)'] = "site/getDealersCity/$2";
路线本质上是冲突的,一条路线会覆盖其他路线。
尝试使用
$route['dealers/(:any)/(:any)'] = "site/getDealersCity/$1/$2";
没有任何功能
getUniqueDealerInfo
在这里查看答案Similar Question