codeigniters のアクティブ レコードを学習し始めており、コントローラーからモデルに渡されたパラメーターを使用してデータベースにクエリを実行しています。
最初に、コントローラーからモデルにIDを渡していますが、それは機能します。
コントローラ
function bret($id){
$this->load->model('school_model');
$data = $this->school_model->get_city_and_population($id);
foreach ($data as $row)
{
echo "<b>Name Of The City</b>...........". $row['Name'];
echo "<br/>";
echo "<b>Total Population</b>...........".$row['Population'];
}
}
モデル
function get_city_and_population($id){
$this->db->select('Name,Population');
$query = $this->db->get_where('city', array('ID'=>$id));
return $query->result_array();
}
先に進み、失敗することを期待して複数のパラメーターを入力しましたが、これは機能しますが、なぜ機能したのか、何が機能したのかわかりません。
コントローラ
public function parameters($id,$name,$district){
$this->load->model('school_model');
$data = $this->school_model->multiple_parameters($id,$name,$district);
foreach ($data as $row)
{
echo "<b>Total Population</b>...........".$row['Population'];
}
}
モデル
function multiple_parameters($id,$name,$district){
$this->db->select('Population');
$query = $this->db->get_where('city', array('ID'=>$id,'Name'=>$name,'District'=>$district));
return $query->result_array();
}
私の複数のパラメータの例では、私が訪れましたhttp://example.com/env/at/index.php/frontpage/parameters/7/Haag/Zuid-Holland/
ここで、名前 Haag
がid7
にあり、地区がZuid-Holland
これが私の質問です.codeigniterはURLからモデルにパラメーターを渡す方法をどのように知っていますか.次に、私が少し間違っていた場合7/Haag/Zuid-Hollandes/
、そのURLが間違っていることをユーザーにどのように示し、代わりにデフォルト値にフォールバックしますか.パラメーターが間違っている場合に空白を表示するのは?