codeigniter 控制器并获取变量
我是 codeigniter 的新手,我似乎无法理解这个问题。
我有一个人员控制器
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');
}
上面从我的数据库中选择了每个人,我的人员视图 (www.example.com/person/) 显示了一个表格,列出了每个人的 ID 及其姓名。
表中每个人的 id 字段是一个指向包含该人信息的页面的链接 (www.example.com/person/24)。这是正确的还是需要(www.example.com/person/view/24),并在人员控制器中使用名为 view 的方法?
这是否也需要单独的视图,还是可以使用相同的视图来完成?
我确信这非常简单,但我认为如果我得到一个好的答案会更好,这样我就可以开始以正确的方式去做,而不是教自己错误的方法!
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.example.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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这将是一个控制器的事情,而不是一个视图。只是想首先把它放在那里。其次,domain.com/person/24 person 是控制器中函数的名称,在本例中 24 是函数的参数。如果操作正确,您可以通过同一个控制器来处理它(另请注意,在这种情况下,24将是index()函数参数,即:index($variable)
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)