-1
我在正確顯示我網站的網址時遇到問題。我正在使用最新版本的Codeigniter。Codeigniter PHP缺少參數2錯誤?
我收到以下錯誤消息。我正在做一些研究,我認爲我的問題是URI段,但我很困惑如何解決這個問題。
我的目標是讓URL看起來不錯這 (_states是子目錄文件夾在我的本地) mydomain.com/_states/dealers/Florida(此URL實際工作) mydomain.com/_states/經銷商/佛羅里達州/邁阿密(不工作) 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'] = '';
的幫助表示感謝嘗試。它工作得很好! –