retrieve parameters from url and build dynamic queries |
Hi everyone, I'm new with codeigniter. I have this problem. I have a western table with data and a view that shows everything. Procedural php code use when I wanted to generate an art director page I put the link followed by? :
director? id_regista = $ id_regista then I went to the landing page and filled in the select with the recovery in GET. But here on codeigniter it doesn't work! I've tried several model-like things: SOLUTION A: Details VIEW: echo "<h5><a href='index.php/western/regista/$id_regista/'>.$row->regia</a></h5>"; Details MODEL: function regista() { $id_regista= $this->uri->segment(3); $query = $this->db->select('*') ->from('western') ->where('id_regista', '$id_regista') // Condition ->get(); return $query->result(); } ___________________________________________________________________________________________________________ OR SOLUTION B VIEW: echo "<h5><a href='index.php/western/regista?id_regista=$id_regista'>.$row->regia</a></h5>"; Model: function regista1() { echo $this->input->get('$id_regista'); $query = $this->db->query("SELECT * FROM western where 'id_regista' = '$id_regista'"); if ($query->num_rows() == 0) { show_error('empty db!'); } else { return $query->result(); } } but both solutions do not dynamically generate the corresponding director for me starting from the home director link. How do I retrieve the parameter and fill the query to build the page since $id_regista = $_GET['id_regista']; put in model don't work? For either solution A or B use in the Western controller function regista() { $this->load->model('western_model'); $data['result'] = $this->western_model->regista(); $this->load->view('regista_view', $data); } and I also bothered to insert in the index $this->load->helper('url'); thanks in advance on some helpful tips to solve, I have tried everything but I can't solve the parameter capture problem either using GET or segment
Is this for CI3 or 4?
Look at the tutorial for a simple example: For CI4: http://codeigniter.com/user_guide/tutori...ction.html For CI3: http://codeigniter.com/userguide3/tutori...ction.html Don't get the id from the model, add a parameter $id_regista to your controller. Something like that: PHP Code: public function regista ($id_regista = NULL)
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/ |
Welcome Guest, Not a member yet? Register Sign In |