I'm developing a system with codeigniter, in my situation i have to press a link in one user interface and get it's ID and pass it to the model and get the data rele开发者_运维百科vant to that ID and go to the other interface and display the data in the relevant fields, i know how to pass data from model to view, but i don't know how to pass to model from the view, can you guys please help me?
(this is my first CI project)
regards, Rangana
You can pass information between pages in several different ways... here's an example:
Your link: http://example.com/controller/method/id/15
$uri = $this->uri->uri_to_assoc();
$this->load->model('model');
$this->model->handleInput($uri['id']);
The above code will pass the id in the URL to the model method handleInput. Let's say your URL looks like this: http://example.com/controller/method/15 - assuming the ID segment in the URL is always in the same place, that is, after the controller and the method, you can retrieve it like this:
$id = $this->uri->segment(3);
$this->load->model('model');
$this->model->handleInput($id);
You can also pass data using the post method. You can retrieve safe post values using the post function, like this:
$id = $this->input->post('id');
$this->load->model('model');
$this->model->handleInput($id);
精彩评论