codeigniter controllers and get variables
Im new to codeigniter, and i cant seem to get my head around this.
I have a person controller
function index()
{
$this->load->model('person_model');
$headData['title'] = 'Person';
$data['records'] = $this->person_model->getAll();
$this->load->view('header', $headData);
//$this->load->view('db_options_view');
$this->load->view('person_view', $data);
$this->load->view('footer');
}
The above selects every person from my database, and my person view (www.exampl开发者_Go百科e.com/person/) displays a table listing each persons id and their name.
The id field of each person in the table is a link to a page with information just about that person (www.example.com/person/24). Is this correct or would it need to be (www.example.com/person/view/24), with a method called view in the person controller?
Would this require a separate view as well, or could it be done with the same view?
Im sure this is pretty straightforward but I thought it would be better if i got a good answer so i can start off doing it the correct way rather than teaching myself the wrong way to do it!
This would be a controller thing, not a views. Just want to put that out there first and foremost. Secondly it would be domain.com/person/24 person being the name of the function in the controller and 24 in this case being the parameter for the function. And if done correctly you could handle it through the same controller (also note 24 in this case would be the index() functions parameter ie: index($variable)
精彩评论