![]() |
how to edit - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: how to edit (/showthread.php?tid=8696) Pages:
1
2
|
how to edit - El Forum - 05-27-2008 [eluser]Mitja[/eluser] This is my code Code: $id = $this->uri->segment(3); //segment iz URLja how can i in view/admin/arrangement_edit use this function without foreach. Code: <tr><td><input type="text" name="title" value="<?= $query->title?>"></td></tr> Ofcourse this is not working, how must i use it? how to edit - El Forum - 05-27-2008 [eluser]Derek Allard[/eluser] The short answer is, use foreach. It is specifically there to help you get through these types of structures. how to edit - El Forum - 05-27-2008 [eluser]Michael Wales[/eluser] A few things here - we'll just chomp them down one at a time. Code: $id = $this->uri->segment(3); //segment iz URLja This is usually much easier to write as a parameter of the method - because then you can test for failure and degrade gracefully: Code: function my_method($id = NULL) { This code is merely going to return TRUE or FALSE. Code: $data['query'] = $this->db->get_where('arrangement', array('arrangement_id' => $id)); All of the Active Record functions return TRUE/FALSE based on whether the query was successfully executed at your database. Based on your foreach() discussion, it seems as if you are just trying to return a single result (if you have more than one you pretty much always want to use foreach()), so I'll show you that. Code: $query = $this->db->get_where('arrangement', array('arrangement_id' => $id), 1, 0); Hope that gets you going in the right direction and if you need further help, just ask! how to edit - El Forum - 05-28-2008 [eluser]Mitja[/eluser] thx for answer Code: function my_method($id = NULL) { i add this function in model. But how can i with this function check if segment is integer ot string and if database query is not null? I try to write a function which check if segment is integer and databse query is not null bot not working. Thx how to edit - El Forum - 05-28-2008 [eluser]Chris Newton[/eluser] Code: if (is_int($this->uri->segment(3)) { Code: $data['query'] = $this->db->get_where('arrangement', array('arrangement_id' => $id)); how to edit - El Forum - 05-28-2008 [eluser]Mitja[/eluser] thx but Code: $id = $this->uri->segment(3); //segment iz URLja always thew an excpetion. $id is never int but it is. http://localhost/bewoop/index.php/admin/arrangements_edit/1 $id is 1 how to edit - El Forum - 05-28-2008 [eluser]Rick Jolly[/eluser] Yep, $id is a string. Here is a function that I use to test for an integer string: Code: public static function int_str($num) If you just want to test for a numeric string you can use is_numeric(). how to edit - El Forum - 05-28-2008 [eluser]Mitja[/eluser] Rick Jolly where do you keep this function, under model or somewhere else? I use it like this Code: if ($this->function_model->int_str($id)) Is this ok? I also find that if i cast is_int work ok Code: $id = (int)$this->uri->segment(3); //segment iz URLja how to edit - El Forum - 05-28-2008 [eluser]Rick Jolly[/eluser] I put that function in a static class, but using CI conventions you'd be best to put it in a helper - just drop the static keyword from the function definition. If you cast to int without knowing if the $id is an integer string then you can get unexpected results: Code: $id = 'asdf'; how to edit - El Forum - 05-28-2008 [eluser]Mitja[/eluser] Quote:I put that function in a static class, but using CI conventions you’d be best to put it in a helper - just drop the static keyword from the function definition. what do you mean with just drop the static keyword from the function definition. |