how to edit |
[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?
[eluser]Derek Allard[/eluser]
The short answer is, use foreach. It is specifically there to help you get through these types of structures.
[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!
[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
[eluser]Chris Newton[/eluser]
Code: if (is_int($this->uri->segment(3)) { Code: $data['query'] = $this->db->get_where('arrangement', array('arrangement_id' => $id));
[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/...nts_edit/1 $id is 1
[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().
[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
[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';
[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. |
Welcome Guest, Not a member yet? Register Sign In |